包含“con”时ASP.NET MVC中出现奇怪的404错误

时间:2012-04-24 16:08:27

标签: asp.net-mvc

我正在浏览我维护的MVC应用程序上的一些爬网错误,并发现一个看似它应该有效的URL的404错误。

网址格式为:/gifts/{categoryName}/{productName}/{productId}/

由于某种原因,当productName设置为值“con”时,我只得到404错误。任何其他值(不同或相同长度的字符串),它似乎工作正常。

有没有人见过这样的事情?

1 个答案:

答案 0 :(得分:19)

con是保留字,因此不能放入MVC路由

您需要将以下内容添加到您的web.config:

<configuration>
  <system.web>
    <httpRuntime relaxedUrlToFileSystemMapping="true"/>

    <!-- ... your other settings ... -->
  </system.web>
</configuration>

有关更多信息,请参阅此文章:

Putting the Con (COM1, LPT1, NUL, etc.) Back in your URLs