c# - .NET UrlEncode not working? -


according http://www.w3schools.com/tags/ref_urlencode.asp when requests submitted url encoded, example space gets transformed %20. far good.

i have problem !. submitting in form converts %21 should. httputility.urlencode (or webutility partner) or uri.escapedatastring return ! expected behaviour? how should encode input c# converts proper values?

an exclamation mark considered url-safe ascii character , therefore not percentage encoded.

from msdn

the urlencode method url-encodes character not in set of ascii characters considered url-safe. spaces encoded ascii "+" character. url-safe ascii characters include asci characters (a z , z), numerals (0 9), , punctuation marks. following table lists punctuation marks considered url-safe ascii characters.

the table contains - _ . ! * ( )

update

according this answer, uri.escapedatastring should encode ! when targetting .net 4.5 projects i'm unable test on current machine. escapedatastring on previous .net frameworks not percentage encode characters above. may need use string.replace , replace characters above escaped uri.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -