Created
May 6, 2014 17:54
-
-
Save xabikos/8a49cd5911cb9189ed7d to your computer and use it in GitHub Desktop.
Action fileter attribute that tiggers a redirect in a specific action method of controller when the user has not confirmed his email in an ASP.NET MVC 5 application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)] | |
public class UserConfirmedFilterAttribute : ActionFilterAttribute | |
{ | |
public override void OnActionExecuting(ActionExecutingContext filterContext) | |
{ | |
var userId = filterContext.HttpContext.User.Identity.GetUserId(); | |
var userManager = filterContext.HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>(); | |
if (!userManager.IsEmailConfirmedAsync(userId).Result) | |
{ | |
filterContext.Result = | |
new RedirectToRouteResult( | |
new RouteValueDictionary(new {controller = "ConstrollerNameToRedirect", action = "ActionMethodToRedirect"})); | |
return; | |
} | |
base.OnActionExecuting(filterContext); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment