내 ASP.NET MVC 5 간단한 멤버 자격 공급자 로그인 코드에 문제가 있습니다.ASP.NET MVC 로그인이 고집하지 않음
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginViewModel model, string returnUrl)
{
bool active = true;
if (ModelState.IsValid && WebSecurity.Login(model.Email, model.Password, persistCookie: model.RememberMe))
{
UserDetail userModel = UserDetail.Initialize(model.Email);
FormsAuthentication.SetAuthCookie(model.Email, true);
active = userModel.ActiveBit;
if (active)
{
return Redirect("~/");
}
else
{
WebSecurity.Logout();
ModelState.AddModelError("", "Account is inactive.");
}
}
else
{
ModelState.AddModelError("", "*Either the Username or Password provided is incorrect.");
}
return View(model);
}
로그인 프로세스를 성공적으로 내가 브라우저에서 인증 쿠키 (.ASPXAUTH)를 볼 수 있습니다 다음과 같이 코드입니다. 문제는 다음 페이지 요청에서 발생합니다. 인증 쿠키는 서버로 다시 전달되지만 서버는 더 이상 로그인 기록이없는 것으로 보입니다. 중단 점을 설정하고 로그인 처리 후 새 페이지를 요청한 후 (로그인 후 리디렉션 완료 후) User.Identity.IsAuthenticated는 WebSecurity.IsAuthenticated 및 WebSecurity.HasUserID와 마찬가지로 false입니다. WebSecurity.CurrentUserId는 -1이고 WebSecurity.CurrentUserName은 빈 문자열입니다.
인증에 성공 했으므로 데이터베이스 연결 문제가 아닙니다. 나는 왕복 서버로 돌아가서 나는 아직도 인증되지 않았기 때문에 CurrentUser == -1에 대해 보았던 일반적인 대답은 적용되지 않는 것 같다.
저는 MVC에서 상대적으로 초보자입니다.하지만 저는이 코드에서보기에 상당한 양의 경험을 가진 동료가 있었으며 아무 것도 찾을 수 없었습니다. 당신의 도움을 주셔서 감사합니다.
불행히도 이미 완료되었습니다. 그래도 고마워. –
시간 초과는 어떻게됩니까? <인증 모드 = "양식"> <형태 loginUrl = "~/계정/로그인"타임 아웃 = "2880"/는> 인증> –
DSR
시간 제한의 4백80분. –