%20后斜线后面更多的数据会导致ASP.NET MVC 3路由失败? [英] %20 followed by slash followed by more data causes ASP.NET MVC 3 routing to fail?
问题描述
在20%出现在PARAMATERS URL之间的人物,我的MVC路由停止考虑的字符串。
这是为什么,以及如何我走近我的URL处理%20字符?
为例网址
的http://本地主机:40494 / ListContents /删除/航空自卫队%20 / 5430f394 ...公众的ActionResult删除(字符串DNSNAME,的Guid ID)
{...}routes.MapRoute(
删除,//路线名称
ListContents /删除/ {} DNSNAME /(编号),// URL带参数
新{控制器=ListContents,行动=删除} //参数默认
);
然而
下面两个网址,做工精细
的http://本地主机:40494 / ListContents /删除/航空自卫队%20SOMETHING_HERE / 5430f394 ...HTTP://本地主机:40494 / ListContents /删除/%20asdf / 5430f394-946c-4f82-ac13-9d5efafe9127
如果一个空的空间是下一个斜线之前的URL的任何部分的结尾,它抛出一个 HttpException
在由MVC处理,你会得到一个HTTP 404响应 System.Web.Util.FileUtil.CheckSuspiciousPhysicalPath()
方法。
您可以通过检查中的复选框扔
验证一下:
-
的Visual Studio
-
调试
-
例外
-
公共语言运行库异常
通常你不应该有空格在您的网址。我个人格式化我的网址,所有的空间变成一个破折号( - )。
When the characters %20 appears in between paramaters a url, my MVC routing stops considering that a string.
Why is that, and how can I approach handling "%20" characters in my URL?
Example URL
http://localhost:40494/ListContents/Delete/asdf%20/5430f394...
public ActionResult Delete(string DNSName, Guid id)
{...}
routes.MapRoute(
"Delete", // Route name
"ListContents/Delete/{DNSName}/{id}", // URL with parameters
new { controller = "ListContents", action = "Delete" } // Parameter defaults
);
However Both the following URLs work fine
http://localhost:40494/ListContents/Delete/asdf%20SOMETHING_HERE/5430f394...
http://localhost:40494/ListContents/Delete/%20asdf/5430f394-946c-4f82-ac13-9d5efafe9127
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 (-).
这篇关于%20后斜线后面更多的数据会导致ASP.NET MVC 3路由失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!