asp.net.ph

Server.UrlEncode Method ( String )

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;

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

HttpServerUtility Members   HttpServerUtility.UrlEncode Overload List 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