Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC 4 Web API fails to map path containing the string "con"?

What is so wrong about the string "con"?

OK, my api route configuration is rather uninteresting:

config.Routes.MapHttpRoute(
    name: "DefaultApi",
    routeTemplate: "api/{controller}/{id}",
    defaults: new { id = RouteParameter.Optional }
);

The LocationController has the following method:

public List<LocationViewModel> Get(string id)
{
    return _ds.SearchLocations(id);
}

Everything works as it should, except that I am getting an HTTP 404 error when I try to get the resource like this:

/api/location/con

In this case, the method is not hit. The strange thing is that if I set any other string other than "con" as an id parameter, the controller method is being hit and works correctly!

This is happening while I am debugging my application on localhost with Cassini (same thing with IIS Express). There are no files named "con" in my project directory. After handling app error event, IntelliTrace revealed an HttpException with message: "Failed to map the path '/api/location/con'"...

Any clues? Is this a known bug?

Thanks in advance!

like image 228
Milos Mrdovic Avatar asked Jul 13 '13 00:07

Milos Mrdovic


1 Answers

Certain keywords are not allowed in the URL and CON is one of them. See this. The workaround is to include the following under <system.web> in your Web.config.

<httpRuntime relaxedUrlToFileSystemMapping="true" />
like image 139
Badri Avatar answered Sep 30 '22 08:09

Badri