asp.net.ph

Server.UrlPathEncode Method

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;

Parameters

s
The text to URL-encode.

Return Value

The URL encoded text.

Remarks

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.

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 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>"  );
See Also

HttpServerUtility Members Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph