سؤال

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

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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

Hope this helps.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top