How is Html.Encode() used? What is its purpose, and how is it useful?
Asked
Active
Viewed 778 times
2 Answers
3
It HTML encodes the passed it text - this escapes things to avoid certain types of attacks, such as XSS.
For example:
Html.Encode("<script>alert('hi');</alert>")
Will result in:
<script>alert('hi');</script>
Being output to the page. This ensures that the script will not run.

Oded
- 489,969
- 99
- 883
- 1,009
0
It encodes tags found in text into their html equiv. For example if '&' was received it would be changed into '&'
Hope this helps.

Chris
- 3,191
- 4
- 22
- 37