C# 表单身份验证asp.net mvc未进行身份验证
当我尝试登录时,FormsAuthentication不起作用。它成功登录并保存会话。将我重定向到索引视图后,@FormsAuthentication.IsEnabled的值为falseC# 表单身份验证asp.net mvc未进行身份验证,c#,asp.net-mvc-5,forms-authentication,C#,Asp.net Mvc 5,Forms Authentication,当我尝试登录时,FormsAuthentication不起作用。它成功登录并保存会话。将我重定向到索引视图后,@FormsAuthentication.IsEnabled的值为false [HttpPost] public ActionResult Login(Models.User user) { if (IsValid(user.Username, user.Password)) {
[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();
}
您正在使用的浏览器的名称/版本是什么 如果您正在使用IE11,下面的链接可能会很有用
web.config中的身份验证模式必须是FormsAuthentication属性的Forms。如果启用,则返回true。下面是dotpeek的反编译代码
public static bool IsEnabled
{
get
{
return AuthenticationConfig.Mode == AuthenticationMode.Forms;
}
}
您的模板最初是否使用asp.net标识?如果是这样,它会删除FormsAuthenticationModule,在web.config中查找并取出它。