This is an entry-level asp tutorial. net user logon code. Let's take a look at the code below.
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 );
}
}
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>