【问题标题】:Forms Authentication in .NET 4.5.NET 4.5 中的表单身份验证
【发布时间】:2013-02-03 18:23:14
【问题描述】:

我通常使用表单身份验证作为登录表单

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。有什么更好的方法?

【问题讨论】:

标签: c# asp.net asp.net-4.5


【解决方案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.";
    }
}

【讨论】:

  • 仅执行上述操作对我没有用。它试图访问 sql 存储并失败。最初的问题是关于如何使用 web.config 中指定的用户名/密码进行身份验证。上面的代码 sn-p 不能解决这个问题。是否缺少一个简单的更改?
猜你喜欢
  • 1970-01-01
  • 2023-03-22
  • 2018-02-08
  • 1970-01-01
  • 2013-02-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多