且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ASP.NET MVC 路由与 Windows 中的保留文件名

更新时间:2022-12-08 19:40:55

此问题已在 ASP.NET 4 中解决.http://haacked.com/archive/2010/04/29/allowing-reserved-filenames-in-URLs.aspx

您可以在 web.config 中应用放宽此限制的设置.

<system.web><httpRuntime RelaxUrlToFileSystemMapping="true"/><!-- ...您的其他设置...--></system.web></配置>

希望有所帮助.

In our ASP.NET MVC application, we've noticed that we cannot have The Forbidden DOS File Names—COM1 through COM9, LPT1 through LPT9, CON, AUX, PRN, and NUL—anywhere in our routes. They inevitably result in IIS telling us the file cannot be found, even when we set routing not to check for the existence of files first. How can we work around this?

This has been addressed in ASP.NET 4. http://haacked.com/archive/2010/04/29/allowing-reserved-filenames-in-URLs.aspx

You can apply a setting in web.config that relaxes this restriction.

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

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

Hope that helps.