Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between html.AttributeEncode vs html.Encode?

Tags:

asp.net-mvc

What is the difference between html.AttributeEncode vs html.Encode?

like image 893
Trimack Avatar asked Feb 11 '10 11:02

Trimack


People also ask

What is the difference between URL encoding and HTML encoding?

HTMLEncoding turns this character into "<" which is the encoded representation of the less-than sign. URLEncoding does the same, but for URLs, for which the special characters are different, although there is some overlap.

What is the use of HTML encode?

HTML encoding ensures that text will be correctly displayed in the browser, not interpreted by the browser as HTML. For example, if a text string contains a less than sign (<) or greater than sign (>), the browser would interpret these characters as an opening or closing bracket of an HTML tag.

What is HTML attribute encoding?

HTML attribute encoding is a superset of HTML encoding and encodes additional characters such as ” and '. Before putting untrusted data into JavaScript place the data in an HTML element whose contents you retrieve at runtime. If this is not possible then ensure the data is JavaScript encoded.

When should I use Htmlencode?

Any time you are trying to output data that could include untrusted html, you should use HTMLENCODE . Encodes text and merge field values for use in HTML by replacing characters that are reserved in HTML, such as the greater-than sign ( > ), with HTML entity equivalents, such as &gt; .


1 Answers

AttributeEncode converts only a handful of characters:

  • "
  • &
  • <
  • \

Encode does a full HtmlEncode, encoding any characters that aren't in Html.

like image 190
Nick Craver Avatar answered Oct 23 '22 19:10

Nick Craver