WebAPI 2.2上的Elmah.axd-找不到HTTP资源 [英] Elmah.axd on WebAPI 2.2 - No HTTP Resource was found

查看:137
本文介绍了WebAPI 2.2上的Elmah.axd-找不到HTTP资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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'."}

该服务器是本地服务器(127.0.0.1),甚至在我的web.config Elmah设置中也可以通过这种方式对其进行保护:

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>

我的WebApiConfig看起来像:

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 }
            );
        }

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

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

最后,我的global.asax看起来像这样:

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.

推荐答案

我终于做到了.

通过添加到WebApiConfig.cs文件

By adding to the WebApiConfig.cs file

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

WebApiConfig.cs文件的整个代码如下:

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 }
            );
        }


    }

最后的更改是将其添加到application_start方法下的global.asax中.

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.

这篇关于WebAPI 2.2上的Elmah.axd-找不到HTTP资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆