5

I'm trying to access /elmah.axd in my broswer, but it returns:

{"message":"No HTTP resource was found that matches the request URI 'http://services.domain.com/elmah.axd'."}

The server is local (127.0.0.1) and even on that I have my web.config Elmah settings to secure it this way:

<elmah>
    <security allowRemoteAccess="true" />
</elmah>

My WebApiConfig looks like:

public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            // Locally only you will be able to see the exception errors
            config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.LocalOnly;

            // Web API routes
            config.Routes.IgnoreRoute("elmah", "elmah.axd");
            config.Routes.IgnoreRoute("allemah", "elmah.axd/{*pathInfo}");
            config.Routes.IgnoreRoute("elmahgeneric", "{resource}.axd/{*everything}");
            config.MapHttpAttributeRoutes();

            var jsonFormatter = config.Formatters.OfType<JsonMediaTypeFormatter>().First();
            jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

            // Remove the XML formatter
            config.Formatters.Remove(config.Formatters.XmlFormatter);

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }

I even tried ignoring only one route at the time from any of the 3 combinations and no luck.

finally my global.asax looks like this:

protected void Application_Start()
        {
            GlobalConfiguration.Configure(WebApiConfig.Register);

        }

Any hint or idea of what I could be missing, would be good.

Thanks in advance, really appreciate your time looking into this.

4 Answers 4

11

I finally made it.

By adding to the WebApiConfig.cs file

config.Routes.MapHttpRoute("AXD", "{resource}.axd/{*pathInfo}", null, null, new StopRoutingHandler());

The entire code of the WebApiConfig.cs file looks like this:

public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            // Locally only you will be able to see the exception errors
            config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.LocalOnly;

            // Web API routes
            config.MapHttpAttributeRoutes();

            var jsonFormatter = config.Formatters.OfType<JsonMediaTypeFormatter>().First();
            jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

            // Remove the XML formatter
            config.Formatters.Remove(config.Formatters.XmlFormatter);

            config.Routes.MapHttpRoute("AXD", "{resource}.axd/{*pathInfo}", null, null, new StopRoutingHandler());

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }


    }

And the final change is add this to the global.asax under application_start method

RouteTable.Routes.Ignore("{resource}.axd/{*pathInfo}");

Special thanks all who helped me with this issue.

2
  • Finally found a real answer of this weird problem, thanks @acido Jul 27, 2015 at 8:13
  • 2
    This worked for me, but I only needed the RouteTable.Routes.Ignore("{resource}.axd/{*pathInfo}"); in Applicaiton_Start.
    – Brian
    Sep 18, 2017 at 23:33
5

When I added the following in in the global.asax under the application_start method:

RouteTable.Routes.Ignore("{resource}.axd/{*pathInfo}");

It did not work until I put it above ...

GlobalConfiguration.Configure(WebApiConfig.Register);

The order of the routes that you add to the Routes property is significant, because the application uses the first route in the collection that matches the URL.

https://msdn.microsoft.com/en-us/library/system.web.routing.routetable.routes(v=vs.110).aspx

2

The most likely problem is missing handlers to generate the error page.

Ensure the following handlers are configured your web.config file:

<system.web>
    ...
    <httpHandlers>
      ...
      <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
    </httpHandlers>


<system.webServer>
    ...
    <handlers>
      ...
      <add name="Elmah" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
    </handlers>

With those settings in place you should be able to access elmah.axd and secure it as expected.

You can grab a sample config file that was updated from a fresh project as an example here: https://brutaldev.com/download/30987439.zip

1
  • I found that I needed to move the Elmah handler to be the first entry in the handlers list. Oct 17, 2017 at 2:56
2

For me adding

config.Routes.IgnoreRoute("axd", "{resource}.axd/{*pathInfo}");

to WebApiConfig was enough.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.