我能够验证登录页面的简单方法。如何在 3 层架构中进行身份验证?请有人向我发送 DAL、BAL 和 GUI 层中应该包含什么的代码?这是我的简单代码:
网络配置:
<authentication mode="form">
<form loginurl="Login.aspx">
<credential password Format="clear">
<user name="abcd" password="1234">
</credential>
</authentication>
</form>
<authorization>
<deny users="?">
</authorization>
登录.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");
}