System.Uri and the encoded colon (:)

Prior to .Net 4.5, it seems that System.Uri will decrypt encoded slashes, but has since been fixed. Link: stack overflow

I ran into the same colon issue. System.Uri still decrypts the encoded colons. Example:

        var uri = new Uri("http://www.example.com/?foo=http%3A%2F%2Fwww.example.com");
        var s = uri.ToString(); //http://www.example.com/?foo=http:%2F%2Fwww.example.com

Note that %3Aswitches :to System.Uri. This is mistake? What is the best workaround?

+6
source share
1 answer

How to use Uri.AbsoluteUriinstead?

var s = uri.AbsoluteUri; 
// http://www.example.com/?foo=http%3A%2F%2Fwww.example.com

uri.ToString() , , , , .AbsoluteUri .

Uri.ToString()

MSDN System.Uri.ToString():

String, Uri. , #,? %.

, , , :, * spaces

%3A (:) // gets unescaped
%20 ( ) // gets unescaped 
%2A (*) // gets unescaped

%2b, %26, %23, %24, %25 (+, &, #, $, %) // Remain as-is (escaped)

+4

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


All Articles