I've got a wildcard route mapped as below:
开发者_JAVA技巧 routes.MapRoute(
null,
"{controller}/{action}/{*category}",
new { controller = "Mall", action = "Index", category = UrlParameter.Optional }
);
This has been working fine until the category has any spaces before or after slashes " / ".
For the category ART/MUSIC, it will find the page fine.
For the category ART / MUSIC, it will give me a 404 not found.
Any help would be much appreciated!
I've just answered kind of the same question here. For completeness:
If an empty space is at the end of any section of the URL before the next slash, it throws a HttpException
in the System.Web.Util.FileUtil.CheckSuspiciousPhysicalPath()
method which is handled by MVC and you'll get a HTTP 404 response.
You can verify that yourself by checking the checkbox for Throw
in:
Visual Studio
Debug
Exceptions
Common Language Runtime Exceptions
Generally you should not have empty spaces in your URLs. I personally format my urls, that all spaces becomes a dash (-).
精彩评论