Reputation: 34798
Is there a .NET encoding method I could use to encode a URL to be passed within a URL parameter?
For example say I have:
url_of_interest = "http://asdf.asdf/asdf.htm"
and I want to include this as one (1) URL form parameter when I do an upload to a web-application:
http://mywebservice/upload?url=<<encoded URL here>>
Upvotes: 6
Views: 2587
Reputation: 9516
As System.Web is being decommissioned from a modern OWIN based application, the alternative solution to HttpUtility.UrlEncode
should be WebUtility.UrlEncode
Upvotes: 1
Reputation: 4789
You should use MS Anti XSS library's
AntiXss.UrlEncode method
The AntiXSS library can be downloaded from the following location
Upvotes: 1
Reputation: 38298
HttpServerUtility.UrlEncode should do the trick:
http://msdn.microsoft.com/en-us/library/zttxte6w.aspx
Upvotes: 2
Reputation: 41872
The UrlEncode() method can be used to encode the entire URL, including query-string values. If characters such as blanks and punctuation are passed in an HTTP stream, they might be misinterpreted at the receiving end. URL encoding converts characters that are not allowed in a URL into character-entity equivalents; URL decoding reverses the encoding. For example, when embedded in a block of text to be transmitted in a URL, the characters < and > are encoded as %3c and %3e.
Upvotes: 1