42

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?

Benjamin Pollack
  • 27,594
  • 16
  • 81
  • 105

4 Answers4

38

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.

Haacked
  • 58,045
  • 14
  • 90
  • 114
  • @thekaid: Backwards compatibility: MS cannot be certain no-one depends on the old behaviour. – Richard May 04 '10 at 11:05
  • 1
    @thekaido What Richard said is exactly right. You'd be surprised at the types of bugs people start to rely on. – Haacked May 10 '10 at 03:32
18

Since asking the question, I've found that the bug is in ASP.NET proper, not IIS or ASP.NET MVC, meaning that there's no way to work around it. The only solution is to manually forbid URLs matching these names and these names followed by a period and random characters.

Benjamin Pollack
  • 27,594
  • 16
  • 81
  • 105
  • 3
    Yup. :) The ASP.NET team is aware of this bug and is looking into it for ASP.NET 4. Can't guarantee if it will be fixed, but at least there is interest in making this better for developers. – Levi Jun 13 '09 at 01:09
4

For a similar reason, there can't be a web.config tag in StackOverflow.

http://stackoverflow.uservoice.com/pages/1722-general/suggestions/98871-web-config-tag-404-error

CoderDennis
  • 13,642
  • 9
  • 69
  • 105
0

for another similar reason you can't have urls with a dot and a slash Semantic urls with dots in .net

Community
  • 1
  • 1
Jokin
  • 4,188
  • 2
  • 31
  • 30