System.Web Namespace HttpServerUtility Class
URL-encodes the path portion of a URL string and returns the encoded string.
[ VB ]
Public Function UrlPathEncode ( _
ByVal s As String _
) As String
[ C# ]
public string UrlPathEncode (
string s
);
[ C++ ]
public: String* UrlPathEncode (
String* s
);
[ JScript ]
public function UrlPathEncode (
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?title = ASP.NET Features".
[ VB ]
Dim MyURL As String
MyURL = "http://www.contoso.com/articles.aspx?title = ASP.NET Examples"
Response.Write ( "<A HREF = " & Server.UrlPathEncode ( MyURL ) & "> ASP.NET Examples <br>" )
[ C# ]
String MyURL;
MyURL = "http://www.contoso.com/articles.aspx?title = ASP.NET Examples";
Response.Write ( "<A HREF = " + Server.UrlPathEncode ( MyURL ) + "> ASP.NET Examples <br>" );
HttpServerUtility Members