ASP.NET membership password expiration

前端 未结 6 533
感动是毒
感动是毒 2021-01-30 14:24

I am using ASP.NET membership for the authentication of my web app. This worked great for me. I now have to implement password expiration.

If the password has expired th

6条回答
  •  再見小時候
    2021-01-30 15:21

    Further to csgero's answer, I found that you don't need to explicitly add an event handler for this event in ASP.Net 2.0 (3.5).

    You can simply create the following method in global.asax and it gets wired up for you:

    void Application_PostAuthenticateRequest(object sender, EventArgs e)
    {
        if (this.User.Identity.IsAuthenticated)
        {
            // get user
            MembershipUser user = Membership.GetUser();
    
            // has their password expired?
            if (user != null
                && user.LastPasswordChangedDate.Date.AddDays(90) < DateTime.Now.Date
                && !Request.Path.EndsWith("/Account/ChangePassword.aspx"))
            {
                Server.Transfer("~/ChangePassword.aspx");
            }
        }
    }
    

提交回复
热议问题