Skip to content

Instantly share code, notes, and snippets.

@xabikos
Created May 6, 2014 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xabikos/8a49cd5911cb9189ed7d to your computer and use it in GitHub Desktop.
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
[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