0

How is Html.Encode() used? What is its purpose, and how is it useful?

2 Answers 2

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:

&lt;script&gt;alert('hi');&lt;/script&gt;

Being output to the page. This ensures that the script will not run.

Sign up to request clarification or add additional context in comments.

Comments

0

It encodes tags found in text into their html equiv. For example if '&' was received it would be changed into '&amp;'

Hope this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.