HttpServerUtility Class
Provides utility methods for encoding and decoding URL tokens.
public static class HttpServerUtilityInheritance System.Object → HttpServerUtility
Methods
HttpServerUtility.UrlTokenDecode(string) Method
Decodes a URL token into a byte array.
public static byte[] UrlTokenDecode(string input);Parameters
input System.String
The URL token to decode.
Returns
System.Byte[]
A byte array representing the decoded data.
Remarks
This method converts URL-safe characters ('-' and '_') back to their original Base64 equivalents ('+' and '/') and then decodes the Base64 string.
HttpServerUtility.UrlTokenEncode(byte[], Nullable<int>) Method
Encodes a byte array into a URL token.
public static string UrlTokenEncode(byte[]? input, System.Nullable<int> length=null);Parameters
input System.Byte[]
The byte array to encode.
length System.Nullable<System.Int32>
The number of bytes to encode. If null, encodes the entire array.
Returns
System.String
A URL-safe token representing the encoded data.
Exceptions
System.ArgumentOutOfRangeException
Thrown when the specified length is greater than the actual length of the input array.
Remarks
This method first converts the byte array to a Base64 string, then replaces Base64-specific characters ('+' and '/') with URL-safe characters ('-' and '_'), and trims any trailing '=' characters.