ASP.NET MVC removes double slashes with query parameters

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

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

The request is as follows: http://localhost:37779/api/get/http:%2F%2Fwww.mysite.com But at some level, the application automatically replaces the double slashes with one.

enter image description here

Where is this going? Is there a way to prevent this behavior? Thank.

+4
source share
2 answers

, , URL-, , URL-. URL- , URL-, ( ) ( GET) ( POST).

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

@tvanfosson , , URL-. blog post, , , .

, :

http://localhost:37779/api/get/http%253A%252F%252Fwww.mysite.com

:

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

web.config , :

<system.webServer>
    <security>
      <requestFiltering allowDoubleEscaping="true"/>
    </security>
</system.webServer>

, : / 400 Bad Request:

<system.web>
    <httpRuntime requestPathInvalidCharacters="&lt;,&gt;" />
</system.web>
+1

Source: https://habr.com/ru/post/1529846/


All Articles