I got here looking for a solution to this but my current technology is ASP.NET MVC. So to help others: you can extend the AuthorizeAttribute
, and override OnAuthorization
method, like this:
public class ExpiredPasswordAttribute : AuthorizeAttribute
{
public override void OnAuthorization(AuthorizationContext filterContext)
{
IPrincipal user = filterContext.HttpContext.User;
if(user != null && user.Identity.IsAuthenticated)
{
MembershipUser membershipUser = Membership.GetUser();
if (PasswordExpired) // Your logic to check if password is expired...
{
filterContext.HttpContext.Response.Redirect(
string.Format("~/{0}/{1}?{2}", MVC.SGAccount.Name, MVC.SGAccount.ActionNames.ChangePassword,
"reason=expired"));
}
}
base.OnAuthorization(filterContext);
}
}
Note: I use T4MVC to retrieve the Controller and Action names in the code above.
Mark all controllers with this attribute except "AccountController
". Doing so no user with an expired password will be able to surf the site.
Here's a post I did on the subject with some bonus points:
User Password Expired filter attribute in ASP.NET MVC