ASP.NET MVC 4的Web API失败映射路径包含字符串" CON"? [英] ASP.NET MVC 4 Web API fails to map path containing the string "con"?

查看:119
本文介绍了ASP.NET MVC 4的Web API失败映射路径包含字符串" CON"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是错的关于字符串骗子?

What is so wrong about the string "con"?

OK,我的API路由配置是相当无趣的:

OK, my api route configuration is rather uninteresting:

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

的LocationController具有以下方法:

The LocationController has the following method:

public List<LocationViewModel> Get(string id)
{
    return _ds.SearchLocations(id);
}

一切正常,因为它应该,但我得到一个HTTP 404错误,当我试图得到这样的资源:

Everything works as it should, except that I am getting an HTTP 404 error when I try to get the resource like this:

/ API /位置/ CON

/api/location/con

在这种情况下,该方法未命中。奇怪的是,假如我不是CON作为ID参数以外的任何其他字符串,该控制器方法被击中并工作正常!

In this case, the method is not hit. The strange thing is that if I set any other string other than "con" as an id parameter, the controller method is being hit and works correctly!

这是当我调试我的应用程序在本地主机上与卡西尼号(与IIS防爆preSS同样的事情)发生。有没有在我的项目目录中名为CON文件。处理应用程序错误事件后,显露的IntelliTrace具有消息的HttpException:未能映射路径'/ API /位置/ CON'......

This is happening while I am debugging my application on localhost with Cassini (same thing with IIS Express). There are no files named "con" in my project directory. After handling app error event, IntelliTrace revealed an HttpException with message: "Failed to map the path '/api/location/con'"...

任何线索?这是一个已知的bug?

Any clues? Is this a known bug?

在此先感谢!

推荐答案

某些关键字未在URL允许和CON就是其中之一。请参见这个。解决方法是包含在以下&LT;的System.Web方式&gt;在你的web.config

Certain keywords are not allowed in the URL and CON is one of them. See this. The workaround is to include the following under <system.web> in your Web.config.

<httpRuntime relaxedUrlToFileSystemMapping="true" />

这篇关于ASP.NET MVC 4的Web API失败映射路径包含字符串&QUOT; CON&QUOT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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