表单身份验证asp.net mvc无法进行身份验证

时间:2015-02-16 00:44:54

标签: c# asp.net-mvc-5 forms-authentication

当我尝试登录时,FormsAuthentication无效。它成功登录并保存会话。在将我重定向到Index视图后,@FormsAuthentication.IsEnabled的值为false。

     [HttpPost]
     public ActionResult Login(Models.User user)
        {
            if (IsValid(user.Username, user.Password))
            {
                FormsAuthentication.SetAuthCookie(user.Username, false);
                Session["Username"] = user.Username;
                Session["IP"] = user.IPAddress;
                return RedirectToAction("Index", "Users");
            }
            else
            {
                ModelState.AddModelError("", "Login Details are wrong!");
            }
            return View();
        }

2 个答案:

答案 0 :(得分:0)

您使用的浏览器的名称/版本是什么?

如果您使用IE 11,

可能是以下链接 https://gyorgybalassy.wordpress.com/2013/09/23/aspnet-40-forms-authentication-issues-with-ie11/

答案 1 :(得分:0)

web.config中的身份验证模式需要是" Forms"使属性FormsAuthentication.Enabled返回true。下面是dotpeek的反编译代码。

public static bool IsEnabled
{
  get
  {
    return AuthenticationConfig.Mode == AuthenticationMode.Forms;
  }
}