System.Web Namespace HttpServerUtility Class
URL encodes a string and sends the resulting output to a TextWriter output stream.
[ VB ]
Overloads Public Sub UrlEncode ( _
ByVal s As String, _
ByVal output As TextWriter _
)
[ C# ]
public void UrlEncode (
string s,
TextWriter output
);
[ C++ ]
public: void UrlEncode (
String* s,
TextWriter* output
);
[ JScript ]
public function UrlEncode (
s : String,
output : TextWriter
);
- s
- The text string to encode.
- output
- The TextWriter output stream containing the encoded string.
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 encodes a string for transmission by HTTP. It encodes the string named TestString, which contains the text "This is a <Test String>.", and copies it into the string named EncodedString as "This+is+a+%3cTest+String%3e.".
[ VB ]
Dim TestString As String = "This is a <Test String>."
Dim writer As New StringWriter
Server.UrlEncode ( TestString, writer )
Dim EncodedString As String = writer.ToString ( )
[ C# ]
String TestString = "This is a <Test String>.";
StringWriter writer = new StringWriter ( );
Server.UrlEncode ( TestString, writer );
String EncodedString = writer.ToString ( );
HttpServerUtility Members HttpServerUtility.UrlEncode Overload List