Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.Net MVC3 routing reserved words?

I have an ASP.Net MVC application with the standard routes defined. The app edits meta data for our database. The url scheme is:

http://localhost/tables/Edit/[Name of Table Here]

This calls the edit function on the tables controller and passes in the name of the table as the parameter id. All of the tables work fine except one named con. The following URL results in a 404:

http://localhost/tables/Edit/con

The only thing I can think of is that con must be some sort of reserved word with respect to MVC routing. Does anyone know whether this is the case and if there are other reserved words to avoid?

like image 233
Ron Avatar asked May 31 '11 23:05

Ron


2 Answers

Yes, con is a reserved word and thus cannot be put in a MVC route. Here is a blog post describing a work-around:

http://haacked.com/archive/2010/04/29/allowing-reserved-filenames-in-URLs.aspx

And another post detailing the reasons behind the reserved words:

http://bitquabit.com/post/zombie-operating-systems-and-aspnet-mvc/

like image 119
aligray Avatar answered Nov 19 '22 01:11

aligray


CON is a reserved word like COM1, COM2, COM3, COM4, LPT1, LPT2, AUX, PRN, NUL.

I also run into this problem while using ajax request. I solved by putting "-" char at the beginning of parameter, and then I replaced it in code-behind.

But it was a silly solution, you can solve this problem easily by simply adding

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

to your Web.config file and you can safely use these words in urls.

like image 28
GorkemHalulu Avatar answered Nov 19 '22 03:11

GorkemHalulu