2014-07-08 1 views
0

나는 asp.net mvc 5를 사용하고 사용자 정의 폼 자동 작성을 사용하고 있습니다. 로그인을 시도 할 때 완벽하게 로그인하려고하지만 로그 오프하려고 할 때 logiurl로 리다이렉션하면 webconfig 파일에 설정되어 있습니다.다른 페이지로의 사용자 지정 양식 자동 로그온 로그 오프 리디렉션?

<authentication mode="Forms"> 
<forms loginUrl="~/Account/Login" timeout="30" /> 
</authentication> 

아래와 같이 재 로그 오프 동작 방법에서 정의 된 페이지 데려다보다는.

[HttpPost] 
[ValidateAntiForgeryToken] 
public ActionResult Logoff() 
{ 
_formsAuth.SignOut(); 
return RedirectToAction("Index", "Home"); 
} 

크롬 브라우저에서는 모든 것이 잘 작동하지만 파이어 폭스에서는 작동하지 않습니다.

답변

0

이 메소드는 더 이상 사용되지 않으므로 테스트에 유용합니다. 더 이상 사용하지 않고 자체 최적화 된 템플릿을 사용하십시오. 보안에 관해서는 고객이 먼저옵니다.

그런데, 나는 당신이 사용하는 클래스와 모델에 대해 의문의 여지가 남아있다.

  • 인증 용 방법은, 사용자에 의해 제공된 인증 정보를 검증 : 폼 인증 기능을 사용

    는 System.Web.Security.FormsAuthentication 클래스의 두 정적 메소드 호출을 필요로한다.

  • SetAuthCookie 메서드는 브라우저에 대한 응답에 쿠키를 추가하므로 사용자가 요청할 때마다 인증 할 필요가 없습니다.
public class FormsAuthProvider : IAuthProvider { 
    public bool Authenticate(string username, string password){ 
     bool result = FormsAuthentication.Authenticate(username, password); 
     if (result) { 
      FormsAuthentication.SetAuthCookie(username, false); 
     } 
     return result; 
    } 


public class AccountController : Controller { 
    IAuthProvider authProvider; 
    public AccountController(IAuthProvider auth) { 
     authProvider = auth; 
    } 
    public ViewResult Login() { 
     return View(); 
    } 
    [HttpPost] 
    public ActionResult Login(LoginViewModel model, string returnUrl) { 
     if (ModelState.IsValid) { 
      if (authProvider.Authenticate(model.UserName, model.Password)) { 

       return Redirect(returnUrl ?? Url.Action("Index", "Admin")); 
      } else { 
       ModelState.AddModelError("", "Incorrect username or password"); 
       return View(); 
      } 
     } else { 
      return View(); 
     } 
    } 
} 
관련 문제