Shashank Sood
Shashank Sood

Reputation: 480

Redirect To Action using ExceptionFilter

I have created an ExceptionFilter:

 public class LogException : FilterAttribute, IExceptionFilter
 {

    void IExceptionFilter.OnException(ExceptionContext filterContext)
    {
        Utility.Log.LogMe(filterContext.Exception);
        filterContext.ExceptionHandled = true;
    }
}

I want to redirect the user to login page whenever this method is hit. How can i do that?

Upvotes: 4

Views: 4230

Answers (1)

user1017882
user1017882

Reputation:

It's important that your ExceptionHandled assignment stays in there, that's a good call, but to redirect too:

        filterContext.Result = new RedirectToRouteResult(
                new RouteValueDictionary 
                { 
                    { "controller", "Account" }, 
                    { "action", "LogIn" } 
                });
        };

Upvotes: 11

Related Questions