0

我正在编写我的 ASP.NET 网站我有一个问题:对于用户身份验证,哪个更好,为什么?

        if ((UserEmail.Text == "oli@yahoo.com") &&
    (UserPass.Text == "1"))
    {

        FormsAuthentication.RedirectFromLoginPage
           (UserEmail.Text, Persist.Checked);
          Response.Redirect("profile.aspx");

    }
    else
    {
        Msg.Text = "Invalid credentials. Please try again.";
    }

或者

        if ((UserEmail.Text == "oli@yahoo.com") &&
    (UserPass.Text == "1"))
    {

        Session["ID"]=UserEmail.Text;
          Response.Redirect("profile.aspx");

    }
    else
    {
        Msg.Text = "Invalid credentials. Please try again.";
    }

请帮我选择正确的表格。

4

1 回答 1

2

如果 FormsAuthentication 设置正确,它将自动将用户重定向到登录页面。如果您自己做,则必须在所有页面上添加代码以确保用户已登录。

关于安全性,只要您使用 SSL,我就会称它们为等价的。FormsAuthentication 对用户 ID 进行加密并将其保存在 cookie 中。Session 只会将会话 ID 存储在 cookie 中。

于 2013-11-14T21:07:52.680 回答