簡單的方法我能夠驗證登錄頁面。我如何在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