简单的方法我能够验证登录页面。我如何在3层体系结构中进行身份验证?请有人向我发送DAL,BAL和GUI图层中的代码?这是我简单的代码:使用asp.net需要登录身份验证的帮助
Web.config文件:
<authentication mode="form">
<form loginurl="Login.aspx">
<credential password Format="clear">
<user name="abcd" password="1234">
</credential>
</authentication>
</form>
<authorization>
<deny users="?">
</authorization>
login.aspx.cs:
sqlconnection con=new sqlconnection("server=localhost;database=dbname;uid=;pwd=;Trusted_Connection=true");
sqldataAdapter da=new sqldataAdapter("select * from Login where UserName='"+TextBox1.Text+"' and Password='"+TextBox2.Text+"'",con);
Dataset ds=new Dataset();
da.Fill(ds);
if(ds.Tables[0].rows.Count>0)
{
if(FormAuthentication.Authenticate("abcd","1234")
{
FormAuthentication.RedirectFromLoginPage(TextBox1.Text,false);
Response.write("Logged in");
}
else
{
Response.write("Unautherised User");
}
Response.Redirect("welcome.aspx");
}
else
{
Response.write("Sorry Invalid UserName or Password");
}
如果我是你,我会把Sqlcommand和sql语句放在DAL中。 BLL应该简单地调用DAL中的函数并传递用户名和密码作为参数。 – Cerebrus 2009-01-28 07:29:57