Code Nugget : is part of the ASP.NET 4.0 web compiler and doesnβt just call Html.Encode() . It turns out whether the first line has already been encoded (if the expression returns IHtmlString , then it probably will not be encoded).
This means that it is safe to use it when pasting actual data or when pasting HTML from some type of helper method (if you are writing your own helper methods, they should always return IHtmlString as from MVC 2).
As for whether you always use it, of course, you do not. But I would rather not think too much about it and would be happier, knowing that I had a little trouble repulsing the XSS attacks with little effort; so I almost always use it.
It also recommends that you return the MvcHtmlString from your HTML helpers, not string .
source share