Search code examples
asp.net-mvcasp.net-mvc-routingelmah

How can I route multiple urls to my Elmah controller


How can I allow multiple urls to access my Elmah error log views?

Right now I am have my web config setup so the url example.com/Admin/ErrorLog goes to the error log and this works nice. I would like the route example.com/ErrorLog to also route to the Elmah views.

Below are the config and route file.

  <appSettings>
    ...
    <add key="elmah.mvc.disableHandler" value="false" />
    <add key="elmah.mvc.disableHandleErrorFilter" value="false" />
    <add key="elmah.mvc.requiresAuthentication" value="true" />
    <add key="elmah.mvc.IgnoreDefaultRoute" value="false" />
    <add key="elmah.mvc.route" value="Admin/ErrorLog" />
    ...
  <appSettings>

Nothing special going on in RouteConfig.cs

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");


    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Account", action = "PublicHome", id = UrlParameter.Optional }
    );
}

Solution

  • You could create an ErrorLogController with an Index action returning a redirect result to admin/errorlog. If you don't want the URL to change when requesting /errorlog, set up a rewrite rule in web.config using the URL rewrite module.