Configure Web. Config to verify the current logon. No matter which page is running, the logon Login. aspx page is automatically displayed if no logon is performed.
Web. Config:
<System. web>
<Authorization>
<Deny users = "? "/>
</Authorization>
<Authentication mode = "Forms">
<Forms loginUrl = "Login. aspx" timeout = "2880" defaultUrl = "Default. aspx"/>
</Authentication>
</System. web>
Login. aspx. cs
Protected void btnLogin_Click (object sender, EventArgs e)
{
String userName = txtUserName. Text;
String userPwd = txtUserPwd. Text;
UserInfo userObj = usermetadata. CheckLogin (userName, userPwd );
If (userObj = null)
Response. Write ("<script> alert ('user name or password is incorrect! '); </Script> ");
Else
{
Session ["UserInfo"] = userObj;
FormsAuthentication. SetAuthCookie (userObj. UserName, false );
Response. Cookies. Add (new HttpCookie ("UserName", userObj. UserName ));
Response. Redirect (FormsAuthentication. DefaultUrl );
}
}