替换过时的 FormsAuthentication.Authenticate

本文关键字:Authenticate FormsAuthentication 过时 替换 | 更新日期: 2023-09-27 17:55:53

Visual Studio 2012警告说,这个类的第一行已经过时了:

if (FormsAuthentication.Authenticate(UserName.Text, Password.Text) == 真)

 public void LoginClass(object s, EventArgs e)
{
    if (FormsAuthentication.Authenticate(UserName.Text, Password.Text) == true)
    {
        FormsAuthentication.SetAuthCookie(UserName.Text, true);
        Response.Redirect("admin/default.aspx");
    }
    else
    {
        if (DBAuthenticate(UserName.Text, Password.Text))
        {
            FormsAuthentication.SetAuthCookie(UserName.Text, true);
            Response.Redirect("members/default.aspx");
        }
        else
        {
            LtlLogin.Text = "<p>Sorry wrong login details</p>";
        }
    }
}

我将不胜感激。我应该用什么替换框架 4.5 中的此类代码行?

替换过时的 FormsAuthentication.Authenticate

错误消息本身或 MSDN 参考页面确实显示了要使用哪些新 API,因此我认为您不需要一些帮助,而是帮助自己,

http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.authenticate(v=vs.110).aspx