0

I've been going through and converting my project to use the <%: instead of the <%= syntax, and have been annoyed that I also have to remove Html.Encode(zoozle) all over the place. If it's left in place, zoozle will get double-encoded.

This leaves me wondering, why doesn't Html.Encode return HtmlString, so that it doesn't get encoded again by <%:?

1 Answer 1

1

The HtmlString is a new class introduced in the .NET 4.0 framework. The HtmlEncode method is on the HttpServerUtility class that has been around since .NET 1.1. Microsoft probably didn't change it so as not to break all the previous implementations that rely on this method returning a string. They can't overload it because you can't overload solely on the return type of a method.

Phil Haacked has a regex that can be used to replace all instances of Html.Encode. http://haacked.com/archive/2010/04/29/replacing-html-encode.aspx

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

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.