[英]Forms authentication asp.net mvc not authenticating
當我嘗試登錄時,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();
}
您使用的瀏覽器的名稱/版本是什么?
如果您使用的是IE 11,可能以下鏈接將非常有用https://gyorgybalassy.wordpress.com/2013/09/23/aspnet-40-forms-authentication-issues-with-ie11/
web.config中的身份驗證模式需要為FormsAuthentication.Enabled
屬性的“Forms”才能返回true。 以下是來自dotpeek的反編譯代碼。
public static bool IsEnabled
{
get
{
return AuthenticationConfig.Mode == AuthenticationMode.Forms;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.