Saturday, August 2, 2014

FORMS AUTHENTICATION

<authentication mode="Forms">
<forms loginUrl="Login.aspx" timeout="30" defaultUrl="Home.aspx" cookieless="AutoDetect">
<credentials passwordFormat="Clear">
<user name="Shiv" password="pass@123"/>
<user name="Raju" password="pass@123"/>
</credentials>
</forms>
</authentication>
 
<authorization>
            <deny users="?"/>
</authorization> 
 
 
  1.  protected void btnSubmit_Click(object senderEventArgs e)
  2.  {
  3.  Page.Validate();
  4.  if (!Page.IsValid) return;

  5.  if (FormsAuthentication.Authenticate(txtUser.TexttxtPass.Text))
  6.  {
  7.  FormsAuthentication.RedirectFromLoginPage(txtUser.Textfalse);
  8.  }
  9.  else
  10.  {
  11.  msg.Text = "Invalid Username or Password";
  12.  }
  13.  }
  14.  
 private bool Authenticate(string username, string password)
{
// This method authenticates the user for the application.
// In this demonstration application it always returns
// true.
return true;
}
 
 
protected void LogOffLinkButton_Click(object sender, System.EventArgs e)
        {
            FormsAuthentication.SignOut();
            Response.Redirect("~/Security/Login.aspx");
        }  
 
 
FormsAuthentication.RedirectFromLoginPage(UserName.Text.Trim(), true); 

No comments:

Post a Comment