开发者

ASP.NET MVC2 -- How is Html.Encode() used?

开发者 https://www.devze.com 2023-02-04 17:14 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消