After adding ELMAH and changing elmah.mvc.route, the old route is still available

I added ELMAH to my ASP.NET MVC 4..NET 4 web application.

The integration was simple and works well.

I changed the value of "elmah.mvc.route" in the application settings of my web.config to the route "Admin / SiteLog" - now elmah log is displayed on this route

But it still shows up in / elmah for some reason (without CSS style, but with the same content).

How to disable elmah default route?

Integration was done using Elmah.MVC package nuget

+8
asp.net-mvc web-config asp.net-mvc-4 elmah routes
source share
3 answers

This is because the default route (if you have one) will still match Elmah.Mvc.ElmahController.

routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional }); 

Part of the "{controller}" route will find the appropriate controller, whether you want it or not. In this case, this is clearly problematic.

You can add restrictions to your routes using the IRouteConstraint, indicated here . The NotEqual restriction is actually very useful.

 using System; using System.Web; using System.Web.Routing; public class NotEqual : IRouteConstraint { private string _match = String.Empty; public NotEqual(string match) { _match = match; } public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection) { return String.Compare(values[parameterName].ToString(), _match, true) != 0; } } 

So, exclude the ElmahController from the default route using the following.

 routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional }, new { controller = new NotEqual("Elmah") }); 

This will cause / elmah to return 404.

+9
source share

I just worked through this problem myself, and in the latest version there seem to be a few app settings that work well enough for this.

 <add key="elmah.mvc.IgnoreDefaultRoute" value="true" /> <add key="elmah.mvc.route" value="admin/elmah" /> 

You may also need to know about others, so pay attention to the default setting.

 <add key="elmah.mvc.disableHandler" value="false" /> <add key="elmah.mvc.disableHandleErrorFilter" value="false" /> <add key="elmah.mvc.requiresAuthentication" value="false" /> <add key="elmah.mvc.allowedRoles" value="*" /> <add key="elmah.mvc.allowedUsers" value="*" /> 
+15
source share

You can specify the location by updating the path in the httpHandlers section in the web.config file

  <httpHandlers> <add verb="POST,GET,HEAD" path="admin/elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah"/> </httpHandlers> 
-one
source share

All Articles