开发者

ASP.NET MVC 2 wildcard route has trouble handling spaces

开发者 https://www.devze.com 2023-01-20 07:33 出处:网络
I\'ve got a wildcard route mapped as below: 开发者_JAVA技巧routes.MapRoute( null, \"{controller}/{action}/{*category}\",

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:

  1. Visual Studio
  2. Debug
  3. Exceptions
  4. 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 (-).

0

精彩评论

暂无评论...
验证码 换一张
取 消