HttpUtility.HtmlAttributeEncode Method

Definition

Minimally converts a string into an HTML-encoded string.

Overloads

HtmlAttributeEncode(String)

Minimally converts a string to an HTML-encoded string.

HtmlAttributeEncode(String, TextWriter)

Minimally converts a string into an HTML-encoded string and sends the encoded string to a TextWriter output stream.

HtmlAttributeEncode(String)

Source:
HttpUtility.cs
Source:
HttpUtility.cs
Source:
HttpUtility.cs

Minimally converts a string to an HTML-encoded string.

C#
public static string? HtmlAttributeEncode(string? s);
C#
public static string HtmlAttributeEncode(string s);

Parameters

s
String

The string to encode.

Returns

An encoded string.

Remarks

The HtmlAttributeEncode method encodes characters appropriate for insertion into an HTML attribute value.

The string result from the HtmlAttributeEncode method should be used only for double-quoted attributes. Security issues might arise when using the HtmlAttributeEncode method with single-quoted attributes.

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

HtmlAttributeEncode(String, TextWriter)

Source:
HttpUtility.cs
Source:
HttpUtility.cs
Source:
HttpUtility.cs

Minimally converts a string into an HTML-encoded string and sends the encoded string to a TextWriter output stream.

C#
public static void HtmlAttributeEncode(string? s, System.IO.TextWriter output);
C#
public static void HtmlAttributeEncode(string s, System.IO.TextWriter output);

Parameters

s
String

The string to encode.

output
TextWriter

A TextWriter output stream.

Remarks

The HtmlAttributeEncode method converts only double quotation marks ("), single quotation marks ('), ampersands (&), and left angle brackets (<) to equivalent character entities. It is considerably faster than the HtmlEncode method.

The string result from the HtmlAttributeEncode method should be used only for double-quoted attributes. Security issues might arise when using the HtmlAttributeEncode method with single-quoted attributes.

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1