AntiXssEncoder.UrlEncode 方法
定义
编码用于 URL 的字符串和字节数组。Encodes strings and byte arrays for use in a URL.
重载
| UrlEncode(String) |
为 URL 编码指定字符串。Encodes the specified string for use in a URL. |
| UrlEncode(String, Int32) |
通过使用指定代码页为 URL 编码指定字符。Encodes the specified string for use in a URL by using the specified code page. |
| UrlEncode(String, Encoding) |
通过使用指定字符编码类型为 URL 编码指定字符。Encodes the specified string for use in a URL by using the specified character encoding type. |
| UrlEncode(Byte[], Int32, Int32) |
编码用于 URL 的指定字节数组,从字节数组指定的偏移开始,并解码指定字节数。Encodes the specified byte array for use in a URL, starting at the specified offset in the byte array and encoding the specified number of bytes. |
UrlEncode(String)
为 URL 编码指定字符串。Encodes the specified string for use in a URL.
public:
static System::String ^ UrlEncode(System::String ^ input);
public static string UrlEncode (string input);
static member UrlEncode : string -> string
Public Shared Function UrlEncode (input As String) As String
参数
- input
- String
要编码的字符串。The string to encode.
返回
编码的字符串。The encoded string.
注解
此方法对不安全列表中的所有字符进行编码。This method encodes all characters except those that are in the safe list. 使用表示法对字符进行编码 %SINGLE_BYTE_HEX 。Characters are encoded by using %SINGLE_BYTE_HEX notation.
下表列出了默认的安全字符。The following table lists the default safe characters. 所有字符均来自 Unicode C0 控件和基本拉丁 字符范围。All characters are from the Unicode C0 Controls and Basic Latin character range.
| 字符Character(s) | 说明Description |
|---|---|
| A-ZA-Z | 大写字母字符Uppercase alphabetic characters |
| a-za-z | 小写字母字符Lowercase alphabetic characters |
| 0-90-9 | 数字Numbers |
| - | 连字符,减Hyphen, minus |
| .. | Period、句点、full stopPeriod, dot, full stop |
| 强调Underscore | |
| ~ | 波形符Tilde |
下表列出了输入和相应编码输出的示例。The following table lists examples of inputs and the corresponding encoded outputs.
alert('XSS Attack!'); |
alert%28%27XSS%20Attack%21%27%29%3b |
<script>alert('XSS Attack!');</script> |
%3cscript%3ealert%28%27XSS%20Attack%21%27%29%3b%3c%2fscript%3e |
alert('XSSあAttack!'); |
alert%28%27XSS%e3%81%82Attack%21%27%29%3b |
user@contoso.com |
user%40contoso.com |
"Anti-Cross Site Scripting Namespace" |
%22Anti-Cross%20Site%20Scripting%20Namespace%22 |
适用于
UrlEncode(String, Int32)
通过使用指定代码页为 URL 编码指定字符。Encodes the specified string for use in a URL by using the specified code page.
public:
static System::String ^ UrlEncode(System::String ^ input, int codePage);
public static string UrlEncode (string input, int codePage);
static member UrlEncode : string * int -> string
Public Shared Function UrlEncode (input As String, codePage As Integer) As String
参数
- input
- String
要编码的字符串。The string to encode.
- codePage
- Int32
要用于编码 input 字符串的代码页。The code page to use to encode the input string.
返回
编码的字符串。The encoded string.
注解
此方法对不安全列表中的所有字符进行编码。This method encodes all characters except those that are in the safe list. 使用表示法对字符进行编码 %SINGLE_BYTE_HEX 。Characters are encoded by using %SINGLE_BYTE_HEX notation.
下表列出了默认的安全字符。The following table lists the default safe characters. 所有字符均来自 Unicode C0 控件和基本拉丁 字符范围。All characters are from the Unicode C0 Controls and Basic Latin character range.
| Unicode 代码图表Unicode code chart | 字符Character(s) | 说明Description |
|---|---|---|
| A-ZA-Z | 大写字母字符Uppercase alphabetic characters | |
| a-za-z | 小写字母字符Lowercase alphabetic characters | |
| 0-90-9 | 数字Numbers | |
| - | 连字符,减Hyphen, minus | |
| .. | Period、句点、full stopPeriod, dot, full stop | |
| 强调Underscore | ||
| ~ | 波形符Tilde |
下表列出了输入和相应编码输出的示例。The following table lists examples of inputs and the corresponding encoded outputs.
alert('XSS Attack!'); |
alert%28%27XSS%20Attack%21%27%29%3b |
<script>alert('XSS Attack!');</script> |
%3cscript%3ealert%28%27XSS%20Attack%21%27%29%3b%3c%2fscript%3e |
alert('XSSあAttack!'); |
alert%28%27XSS%e3%81%82Attack%21%27%29%3b |
user@contoso.com |
user%40contoso.com |
"Anti-Cross Site Scripting Namespace" |
%22Anti-Cross%20Site%20Scripting%20Namespace%22 |
适用于
UrlEncode(String, Encoding)
通过使用指定字符编码类型为 URL 编码指定字符。Encodes the specified string for use in a URL by using the specified character encoding type.
public:
static System::String ^ UrlEncode(System::String ^ input, System::Text::Encoding ^ inputEncoding);
public static string UrlEncode (string input, System.Text.Encoding inputEncoding);
static member UrlEncode : string * System.Text.Encoding -> string
Public Shared Function UrlEncode (input As String, inputEncoding As Encoding) As String
参数
- input
- String
要编码的字符串。The string to encode.
- inputEncoding
- Encoding
输入编码类型。The input encoding type.
返回
编码的字符串。The encoded string.
注解
此方法对不安全列表中的所有字符进行编码。This method encodes all characters except those that are in the safe list. 使用表示法对字符进行编码 %SINGLE_BYTE_HEX 。Characters are encoded by using %SINGLE_BYTE_HEX notation.
下表列出了默认的安全字符。The following table lists the default safe characters. 所有字符均来自 Unicode C0 控件和基本拉丁 字符范围。All characters are from the Unicode C0 Controls and Basic Latin character range.
| 字符Character(s) | 说明Description |
|---|---|
| A-ZA-Z | 大写字母字符Uppercase alphabetic characters |
| a-za-z | 小写字母字符Lowercase alphabetic characters |
| 0-90-9 | 数字Numbers |
| - | 连字符,减Hyphen, minus |
| .. | Period、句点、full stopPeriod, dot, full stop |
| 强调Underscore | |
| ~ | 波形符Tilde |
下表列出了输入和相应编码输出的示例。The following table lists examples of inputs and the corresponding encoded outputs.
alert('XSS Attack!'); |
alert%28%27XSS%20Attack%21%27%29%3b |
<script>alert('XSS Attack!');</script> |
%3cscript%3ealert%28%27XSS%20Attack%21%27%29%3b%3c%2fscript%3e |
alert('XSSあAttack!'); |
alert%28%27XSS%e3%81%82Attack%21%27%29%3b |
user@contoso.com |
user%40contoso.com |
"Anti-Cross Site Scripting Namespace" |
%22Anti-Cross%20Site%20Scripting%20Namespace%22 |
适用于
UrlEncode(Byte[], Int32, Int32)
编码用于 URL 的指定字节数组,从字节数组指定的偏移开始,并解码指定字节数。Encodes the specified byte array for use in a URL, starting at the specified offset in the byte array and encoding the specified number of bytes.
protected public:
override cli::array <System::Byte> ^ UrlEncode(cli::array <System::Byte> ^ bytes, int offset, int count);
protected internal override byte[] UrlEncode (byte[] bytes, int offset, int count);
override this.UrlEncode : byte[] * int * int -> byte[]
Protected Friend Overrides Function UrlEncode (bytes As Byte(), offset As Integer, count As Integer) As Byte()
参数
- bytes
- Byte[]
要编码的字节数组。The byte array to encode.
- offset
- Int32
要解码的第一个字节的索引。The index of the first byte to encode.
- count
- Int32
要编码的字节数。The number of bytes to encode.
返回
- Byte[]
这些编码的字节数组。The encoded byte array.
注解
此方法对不安全列表中的所有字符进行编码。This method encodes all characters except those that are in the safe list. 使用表示法对字符进行编码 %SINGLE_BYTE_HEX 。Characters are encoded by using %SINGLE_BYTE_HEX notation.
下表列出了默认的安全字符。The following table lists the default safe characters. 所有字符均来自 Unicode C0 控件和基本拉丁 字符范围。All characters are from the Unicode C0 Controls and Basic Latin character range.
| 字符Character(s) | 说明Description |
|---|---|
| A-ZA-Z | 大写字母字符Uppercase alphabetic characters |
| a-za-z | 小写字母字符Lowercase alphabetic characters |
| 0-90-9 | 数字Numbers |
| - | 连字符,减Hyphen, minus |
| .. | Period、句点、full stopPeriod, dot, full stop |
| 强调Underscore | |
| ~ | 波形符Tilde |
下表列出了输入和相应编码输出的示例。The following table lists examples of inputs and the corresponding encoded outputs.
alert('XSS Attack!'); |
alert%28%27XSS%20Attack%21%27%29%3b |
<script>alert('XSS Attack!');</script> |
%3cscript%3ealert%28%27XSS%20Attack%21%27%29%3b%3c%2fscript%3e |
alert('XSSあAttack!'); |
alert%28%27XSS%e3%81%82Attack%21%27%29%3b |
user@contoso.com |
user%40contoso.com |
"Anti-Cross Site Scripting Namespace" |
%22Anti-Cross%20Site%20Scripting%20Namespace%22 |