Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

HttpEncoder::UrlEncode Method

Encodes an array of characters that are not allowed in a URL into a hexadecimal character-entity equivalent.

Namespace:  System.Web.Util
Assembly:  System.Web (in System.Web.dll)
protected public:
virtual array<unsigned char>^ UrlEncode(
	array<unsigned char>^ bytes, 
	int offset, 
	int count


Type: array<System::Byte>

An array of bytes to encode.

Type: System::Int32

The position in the bytes array at which to begin encoding.

Type: System::Int32

The number of items in the bytes array to encode.

Return Value

Type: array<System::Byte>
An array of encoded characters.

offset is less than zero or greater than the length of the bytes array.


count is less than zero or count plus offset is greater than the length of the bytes array.


bytes is nullptr.

The UrlEncode method is called by several URL encoding methods in the HttpUtility class.

The UrlEncode method URL-encodes any character that is not in the set of ASCII characters that is considered to be URL-safe. Spaces are encoded as the ASCII "+" character. URL-safe ASCII characters include the ASCI characters (A to Z and a to z), numerals (0 to 9), and some punctuation marks. The following table lists the punctuation marks that are considered URL-safe ASCII characters.








Period (dot)


Exclamation mark


Asterisk (star)


Opening parenthesis


Closing parenthesis

.NET Framework

Supported in: 4.5.1, 4.5, 4

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.