System.Web Namespace HttpServerUtility Class
URL-encodes a string and returns the encoded string.
[ VB ]
Overloads Public Function UrlEncode ( _
ByVal s As String _
) As String
[ C# ]
public string UrlEncode (
string s
);
[ C++ ]
public: String* UrlEncode (
String* s
);
[ JScript ]
public function UrlEncode (
s : String
) : String;
- s
- The text to URL-encode.
The URL encoded text.
URL encoding ensures that all browsers will correctly transmitted text in URL strings. Characters such as "?", "&", "/", and spaces may be truncated or corrupted by some browsers so those characters cannot be used in ASP.NET pages in "<A>" tags or in querystrings where the strings may be sent by a browser in a request string.
The following example URL-encodes a string before sending it to a browser client. In this example, the string MyURL will be encoded as "http%3a%2f%2fwww.contoso.com%2farticles.aspx%3ftitle+%3d+ASP.NET+Examples".
[ VB ]
Dim MyURL As String
MyURL = "http://www.contoso.com/articles.aspx?title = ASP.NET Examples"
Response.Write ( "<A HREF = " & Server.UrlEncode ( MyURL ) & "> ASP.NET Examples <br>" )
[ C# ]
String MyURL;
MyURL = "http://www.contoso.com/articles.aspx?title = ASP.NET Examples";
Response.Write ( "<A HREF = " + Server.UrlEncode ( MyURL ) + "> ASP.NET Examples <br>" );
HttpServerUtility Members HttpServerUtility.UrlEncode Overload List