-1

I usually use the Forms Authentication for a login form as

protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
   if(FormsAuthentication.Authenticate(Login1.UserName, Login1.Password))
     {
        FormsAuthentication.RedirectFromLoginPage(Login1.UserName, Login1.RememberMeSet);
     }
}

and the web.config has

<authentication mode="Forms">
  <forms defaultUrl="Page.aspx">
     <credentials passwordFormat="Clear">
        <user name="Enter here" password="Enter here" />
     </credentials>
  </forms>

</authentication>
<authorization>
  <deny users="?" />
</authorization>

However, this does not work for .NET 4.5. What is a better way?

user544079
  • 16,109
  • 42
  • 115
  • 171

1 Answers1

1
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.";
    }
}
will simmons
  • 189
  • 2
  • Just doing the above hasn't worked for me. It tried to access a sql store and failed. The original question was about how to use username/password specified in web.config for authentication. The code snippet above doesn't solve that. Is there a simple change that is missing? – user1198407 Aug 18 '14 at 23:42