문제

암호가 만료 된 경우 사용자를 암호 변경 페이지로 리디렉션해야합니다.

모든 요청을 암호 변경 페이지로 리디렉션 할 수 있도록이 코드를 한 곳에 배치하고 싶습니다.

나는 승인을 확장하고 onactionExecuting을 재정의하는 것을 살펴 보았지만, 비밀번호 변경 페이지로 리디렉션하기 위해 라우팅 로직을 단락시키지 못하게합니다.

약간의 설명을 위해 논리는 다음과 같습니다.

무단 요청 :
-> 모든 url-> awryizeattribute-> login.aspx-> 비밀번호 만료 -> changepassword.aspx

승인 된 요청 :
-> 모든 url-> ??????? -> ChangePassword.aspx

그게 ???? 나는 무엇을 해야할지 잘 모르겠다.


나는 승인을 확장 할 것이라고 생각합니다. 나는 어디서나 그것을 사용할 것이다 제외하고 암호 변경 컨트롤러 방법.

도움이 되었습니까?

해결책

public class DenyExpiredPasswordAttribute : AuthorizeAttribute
{

    public override void OnAuthorization(AuthorizationContext filterContext)
    {
        IPrincipal user = filterContext.HttpContext.User;

        if(user != null)
        {
            if (user.Identity.IsAuthenticated)
            {

                if (CurrentUser.PasswordExpired) // your checking of password expiration
                {
                    filterContext.HttpContext.Response.Redirect("~/Account/ChangePassword?reason=expired");
                }
            }
        }
        base.OnAuthorization(filterContext);
    }
}

이것은 잘 작동합니다.이 속성으로 모든 컨트롤러를 "계정"을 제외하십시오. 이런 식으로 만료 된 속성을 가진 사용자는 비밀번호를 변경할 때까지 계속할 수 없습니다.

다른 팁

Global.asax에서 이벤트 이벤트 이벤트에 대한 이벤트 핸들러를 추가 할 수 있습니다.

protected void Application_Start(object sender, EventArgs e) {
  this.PostAuthenticateRequest += new EventHandler(Global_PostAuthenticateRequest);
}

void Global_PostAuthenticateRequest(object sender, EventArgs e)
{
 if (passwordExpired) {
   Context.Response.Redirect("~/ChangePassword.aspx");
   }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top