More in this section
Forums / Project Feather / Routing in MVC

Routing in MVC

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
2 posts, 0 answered
  1. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    18 Feb 2004
    07 Sep 2015
    Link to this post

    Hi all, 

    I'm trying to do something with unhandled exceptions.

    For some reason, it is very hard to show an error page if an unhandled exception occurs. I found a way to redirect 404, 403 etc. using an ErrorController. A 500 exception however always shows inside the active MVC view.

    What works is something like this (simplified code): 

       return View("Index", model);
    catch (Exception)
       return RedirectToRoute(ErrorControllerRoute.GetInternalServerError);

    This RedirectToRoute will redirect to:

    I wanted to do something like this in the OnException override of my BaseController class like this:

    protected override void OnException(ExceptionContext filterContext)
       filterContext.Result = RedirectToRoute(ErrorControllerRoute.GetInternalServerError);

    However, that is not working. The URL it generates in this case is:

    So, it looks like the ErrorController class is ignored.

    Any idea how this works within Sitefinity?

  2. Nikola Zagorchev
    Nikola Zagorchev avatar
    424 posts
    19 Apr 2017
    12 Sep 2015
    Link to this post
    Hello Daniel,

    You can redirect to a controller route the following way:
    filterContext.Result = new RedirectToRouteResult(new
                       RouteValueDictionary(new { controller = "Controller", action = "Error"}));

    If you want to show a view for the error, you can use the following:
    public override void OnException(ExceptionContext filterContext)
                Exception ex = filterContext.Exception;
                Log.Write(ex, ConfigurationPolicy.ErrorLog);
                if (!string.IsNullOrEmpty(this.View))
                    this.View = HandleErrorAttributeCustom.defaultErrorView;

    @model HandleErrorInfo

    which you can also place in a attribute inheriting from HandleErrorAttribute.

    Hope the above helps.

    Nikola Zagorchev
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
2 posts, 0 answered