C # ASP.NET HttpWebRequest automatically decodes ampersand (&) values ​​from query string?

Assume the following url:

"http://server/application1/TestFile.aspx?Library=Testing&Filename=Documents & Functions + Properties.docx&Save=true"

I use HttpUtility.UrlEncode () to encode the value of the Filename parameter and create the following URL:

"http://server/application1/TestFile.aspx?Library=Testing&Filename=Documents%20%26%20Functions%20%2B%20Properties.docx&Save=true"

I am sending the next (encoded version) request from a client to a C # web application. On the server, when I process the request, I have a problem. The HttpRequest variable contains a partially decoded query string. That is, when I try to use or quickly track the following HttpRequest properties, they have the following meanings.

Property = Value
================
HttpRequest.QueryString = "{Library=Testing&Filename=Documents+&+Functions+++Properties.docx&Save=true}"

HttpRequest.Url = "{http://server/application1/TestFile.aspx?Library=Testing&Filename=Documents & Functions + Properties.docx&Save=true}"

HttpRequest.Url.AbsoluteUri = "http://server/application1/TestFile.aspx?Library=Testing&Filename=Documents%20&%20Functions%20+%20Properties.docx&Save=true"

I also checked the following properties, but they all have a value and a value decoded. However, all other values ​​remain correctly encoded (for example, the space is% 20).

HttpRequest.Url.OriginalString

HttpRequest.Url.Query

HttpRequest.Url.PathAndQuery

HttpRequest.RawUrl

Filename. - ?

+3
4

QueryString NameValueCollection, .

Request.QueryString["FileName"].

+2

, . , HttpRequest.Url - , . HttpRequest.Url - Uri, ToString() . ToString() Uri Url. HttpRequest.Url.OriginalString. URL-, . , , .

+2

, UrlEncode? , URL-, UrlEncode, , ( URL-).

+1

FWIW RavenDB ( 960). HttpRequest, : ( %26 &), . , .

:

  • . , .
  • . , . ( , , .)
0

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


All Articles