-1

我通常将表单身份验证用于登录表单

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

web.config

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

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

但是,这不适用于 .NET 4.5。有什么更好的方法?

4

1 回答 1

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.";
    }
}
于 2013-02-03T20:44:12.357 回答