0

How to login or authenticate using FormAuthenticate method in ASP.NET web forms and after login how to check on each page whether user is authenticaed or not.

please give me a sample for that how to use form authentication in login page.

3
  • @Blachshma What framework are you using MVC3? MVC4 classic ASP webforms Commented Dec 10, 2012 at 10:13
  • m using the ASP.net web forms. Commented Dec 10, 2012 at 10:13
  • 1
    Have you looked through MSDN documentation? Is there anything specific that you do not understand there? Commented Dec 10, 2012 at 10:35

2 Answers 2

1

1) FormsAuthentication Class - validate user

public void Login_OnClick(object sender, EventArgs args)
{
   if (Membership.ValidateUser(UsernameTextbox.Text, PasswordTextbox.Text))
   {
      FormsAuthentication.RedirectFromLoginPage(UsernameTextbox.Text, NotPublicCheckBox.Checked);
   }
   else
     Msg.Text = "Login failed. Please check your user name and password and try again.";
}

2) How to: Implement Simple Forms Authentication

3) Check if user is logged

if(User.Identity.IsAuthenticated)
{
    //user is logged in
}
else
{
    //user is not logged in
}
Sign up to request clarification or add additional context in comments.

Comments

1

How to: Implement Simple Forms Authentication

The page displays the user's authenticated identity, which was set by the FormsAuthentication class and is available in an ASP.NET page as the Context.User.Identity.Name property.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.