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?
-
11For fun, hit stackoverflow.com/com1 and compare to stackoverflow.com/ThisDoesNotExist– kamensCommented Jun 12, 2009 at 15:09
-
12And leveraging this knowledge, I have now successfully made it impossible to navigate to my user page. Woot.– Benjamin PollackCommented Jun 12, 2009 at 16:49
-
3I like how you DOS'd yourself.– Michael PryorCommented Jun 12, 2009 at 21:15
-
2Very cool; but not impossible - the username isn't required in the user info route ;)– Tom RitterCommented Jun 12, 2009 at 21:27
-
2microsoft.com/com1.aspx ))– Sergey MirvodaCommented Apr 30, 2010 at 19:16
4 Answers
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.
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.
-
3Yup. :) 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.– LeviCommented Jun 13, 2009 at 1:09
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
for another similar reason you can't have urls with a dot and a slash Semantic urls with dots in .net