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.
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.
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
}
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.Nameproperty.