Encoding URL parameters in MVC.NET

I have a controller in an MVC 4.NET application that receives a string as a parameter from a URL. This comes from an aspx page redirected to the controller in Route.config.

If I send this value for the parameter in the client: fwdgerhb+bhrth+ftrgbhrt

I get the following value on the server: fwdgerhb bhrth ftrgbhrt

The server interprets the URL parameter value as an encoded URL and replaces +with . But it was not URL encoded. This will happen for other combinations of special characters if they appear in the parameter value.

Does IIS Server have a configuration parameter to configure the server so as not to try to convert this value to a URL?

Request example:

mypage.aspx?value=cat+dog    (NOT ENCODED)

Route configuration

static void RegisterRoutes(RouteCollection routes)
{
    routes.MapRouteLowercase(
        name: "MyRouter",
        url: "mypage.aspx",
        defaults: new { controller = "My", action = "DoLog" }
    );
}

Controller:

public class MyController : Controller
{
    [AllowAnonymous]
    public ActionResult DoLog(string value)
    {
        //Here value has "cat dog"
    }
}
+4
2

, MVC URL- , URL- . : MVC2 ASP.Net URLDecoding ?

UNENCODED_URL. : URL URL

+7

:

Request.QueryString.Get("value");

, :

Html.ViewContext.HttpContext.Request.QueryString.Get("value");

, , , :

HttpUtility.UrlEncode(value);

, :

HttpUtility.UrlDecode(value);

,


, routeConfig "+":

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

, : ?

+8

All Articles