기본 폼 인증을 사용하여 ASP.NET MVC5 응용 프로그램을 구현하려고합니다. 그래서 내 로그인 방법이있다 :401 FormsAuthentication.SetAuthCookie() 이후에도 인증되지 않음
는[HttpPost]
[AllowAnonymous]
public ActionResult Login(string email, string password, bool? rememberMe)
{
if (email.IsNullOrWhiteSpace() || password.IsNullOrWhiteSpace())
{
return RedirectToAction("Index");
}
UserEntity user = new UserEntity() {Email = email, PasswordHash = password};
var userFromDb = _userService.FindUser(user);
if (userFromDb != null)
{
FormsAuthentication.SetAuthCookie(userFromDb.Name, rememberMe.GetValueOrDefault());
var a = HttpContext.User.Identity.IsAuthenticated; //This is still false for some reson
return RedirectToAction("Index", "User");
}
return RedirectToAction("Index");
}
하지만 지금 리디렉션에이 방법 후 나에게의를 401 Unauthorized
오류를 제공합니다. 또한 HttpContext.User.Identity.IsAuthenticated가 false 인 것 같습니다.
그 이유는 무엇이며 어떻게 수정해야하는지 아이디어/제안이 있습니까?
UPD는 : 그것은 트리거에 대한 그 <system.web>
내 web.config 파일에 이유
<authentication mode="Forms"> <forms loginUrl="~/Login/Index" /> </authentication>
MVC5는 기본적으로 FormsAuthentication을 사용하지 않기 때문입니다. ASP.NET ID를 사용하므로 기본 템플릿에서 FormsAuthentication이 제거됩니다. 이를 대체하면 FormsAuth를 다시 사용할 수 없습니다. –