ASP.NET MVC从请求参数中删除双斜杠 [英] ASP.NET MVC removes double forward slashes from request parameters

查看:193
本文介绍了ASP.NET MVC从请求参数中删除双斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的ASP.NET MVC 4应用程序中,我对控制器进行了一项操作,该操作获取URL字符串作为参数:

In my ASP.NET MVC 4 application I have an action on controller that gets URL string as a parameter:

public ActionResult Get(string url)
{
    var hash = TextUtil.GenerateShortStringHash(url);
    ...
    return Content(html, "text/html");
}

请求如下所示:http://localhost:37779/api/get/http:%2F%2Fwww.mysite.com 但是在某种程度上,应用程序会自动用单斜杠替换双斜杠.

The request looks like this: http://localhost:37779/api/get/http:%2F%2Fwww.mysite.com But on some level application automatically replaces double slashes with single one.

这在哪里发生?有什么办法可以防止这种行为?谢谢.

Where does this happen? Is there any way to prevent such behavior? Thanks.

推荐答案

我的怀疑是,由于它是URL层次结构部分的一部分,因此它会自动将双斜杠转换为单斜杠,因为不允许在其中使用双斜杠. URL的一部分.因为URL包含URL的层次结构部分中不允许的字符,所以最好将其(适当地编码)作为查询字符串(如果是GET请求)的一部分或以表单参数(对于POST)指定./p>

My suspicion is that because it's part of the hierarchical portion of the URL it's automatically converting the double slashes to a single slash because double slashes aren't allowed in that portion of the URL. Because URLs contain characters that aren't allowed in the hierarchical portion of the URL, it's best to specify it (suitably encoded) as part of the query string (if a GET request) or in the form parameters (for a POST).

http://localhost:37779/api/get/?url=http:%2F%2Fwww.mysite.com

这篇关于ASP.NET MVC从请求参数中删除双斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆