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

dot*_*e82 12 asp.net-mvc

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

URL的格式为: /gifts/{categoryName}/{productName}/{productId}/

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

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

Cur*_*urt 20

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

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

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

    <!-- ... your other settings ... -->
  </system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud)

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

将Con(COM1,LPT1,NUL等)放回您的URL