HttpServerUtility.UrlPathEncode Method
URL-encodes the path portion of a URL string and returns the encoded string.
[Visual Basic] 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;
Parameters
- s
- The text to URL-encode.
Return Value
The URL encoded text.
Remarks
URL encoding ensures that all browsers will correctly transmit text in URL strings. Characters such as ?, &,/, and spaces may be truncated or corrupted by some browsers so those characters must be encoded in <A> tags or in query strings where the strings may be re-sent by a browser in a request string.
Example
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 Examples".
[Visual Basic] 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>" ); [C++] String* MyURL; MyURL = S"http://www.contoso.com/articles.aspx?title = ASP.NET Examples"; Response->Write( String::Format( S"<A HREF = {0}> ASP.NET Examples <br>", Server->UrlPathEncode(MyURL) ) ); [JScript] var myURL : String myURL = "http://www.contoso.com/articles.aspx?title = ASP.NET Examples" Response.Write( "<A HREF = " + Server.UrlPathEncode(myURL) + "> ASP.NET Examples <br>")
Requirements
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
See Also
HttpServerUtility Class | HttpServerUtility Members | System.Web Namespace