2
ASP.NET MVC 4로 개발 된 내 웹 사이트에 사용자를 인증하고 권한을 부여하는 로그인 메소드를 작성하려고합니다. 문제는 FormsAuthentication.SetAuthCookie 메소드를 호출 한 후 FormsAuthentication.SetAuthCookie 메소드를 호출했지만 사용자가 Login 메서드 내에서 ViewProfile 작업으로 리디렉션하면 User.Identity.IsAuthenticated가 사용자 지정 Authorize 특성 개체에서 여전히 false를 반환합니다. ASP.NET MVC 4 사용자 인증
나는 아래의 코드 주었다[HttpPost]
[AllowAnonymous]
public ActionResult Login(LoginModel model)
{
if (Membership.ValidateUser(model.Username, model.Password))
{
FormsAuthentication.SetAuthCookie(model.Username, model.RememberMe);
return this.RedirectToAction("ViewProfile");
}
ModelState.AddModelError("", "The user name or password provided is incorrect.");
return View(model);
}
[MyAuthorize(Roles = "Super Role, Seeker")]
public ActionResult ViewProfile()
{
if (ModelState.IsValid)
{
...
}
}
을 그리고 여기에 내가 무엇을 놓치고 오전 MyAuthorizeAttribute 클래스
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class MyAuthorizeAttribute : AuthorizeAttribute
{
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
if (httpContext == null)
throw new ArgumentNullException("httpContext");
var user = httpContext.User;
if (!user.Identity.IsAuthenticated)
return false;
...
}
}
의 코드? 있는 FormsAuthentication를 사용하고 비슷한 상황에 직면, 다음과 같은 구성이 web.config 파일에서 존재한다는 것을 확신 할 수있는 사람을위한
당신이 폼 인증을 볼 수 잘 작동 리디렉션 할 때 후속 통화시 쿠키가 설정되고 전송됩니까? –