RedirectToAction
is protected, and we can use it only inside actions. But if I want to redirect in a filter?
public class IsGuestAttribute: Acti
Security/Authorization/Authentication Filters should use the AuthorizeAttribute and IAuthorizationFilter.
public class IsGuestAttribute: AuthorizeAttribute, IAuthorizationFilter
{
public void OnResultExecuted(ResultExecutedContext filterContext)
{
}
public void OnActionExecuting(ActionExecutingContext filterContext)
{
if (!Ctx.User.IsGuest)
{
filterContext.Result = new RedirectToRouteResult(
new RouteValueDictionary
{
{ "controller", "Home" },
{ "action", "Index" }
});
}
}
}