我试图在我的浏览器中访问/elmah.axd,但返回:

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

服务器是本地的 (127.0.0.1),即使在那里我也有我的 web.config Elmah 设置来保护它:
<elmah>
    <security allowRemoteAccess="true" />
</elmah>

我的 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.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 }
            );
        }

我什至试图同时忽略这3种组合中的任何一条,并且没有运气。

最后我的 global.asax 看起来像这样:
protected void Application_Start()
        {
            GlobalConfiguration.Configure(WebApiConfig.Register);

        }

任何关于我可能遗漏的提示或想法都会很好。

提前致谢,非常感谢您花时间研究这个问题。

最佳答案

我终于做到了。

通过添加到 WebApiConfig.cs 文件

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

WebApiConfig.cs 文件的整个代码如下所示:
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 }
            );
        }


    }

最后的变化是将其添加到 application_start 方法下的 global.asax
RouteTable.Routes.Ignore("{resource}.axd/{*pathInfo}");

特别感谢所有帮助我解决这个问题的人。

10-04 19:17