Urls /lpt1 and /com1 cause IIS to render its own screen of death

一笑奈何 提交于 2019-12-06 10:45:17

Until ASP.NET 4.0 it wasn't possible to use certain reserved filenames such as con, lpt, aux and so in on your urls:

Zombie Operating Systems and ASP.NET MVC

This was a limitation of ASP.NET, not MVC.

However the good news is that it's now possible:

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

If you're not using ASP.NET 4.0, you should be able to catch these 404's using IIS7's own <httpErrors> configuration settings.

With ASP .NET 3.5 you can use an url rewrite rule of the url rewrite module in order to change the url to a valid one.

The url rewite module is:

The Microsoft URL Rewrite Module 2.0 for IIS 7 and above enables IIS administrators to create powerful customized rules to map request URLs to friendly URLs that are easier for users to remember and easier for search engines to find

Something like:

<rewrite>
  <rules>
    <rule name="CON rewrite" stopProcessing="true">
      <match url="(.*)/(con\.)(.*)" />
      <action type="Redirect" url="{R:1}/con-{R:3}" redirectType="SeeOther" />
    </rule>     
  </rules>
</rewrite>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!