开发者

Why doesn't html.encode return HtmlString

开发者 https://www.devze.com 2023-02-03 06:15 出处:网络
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 lef

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.En开发者_如何学Pythoncode return HtmlString, so that it doesn't get encoded again by <%:?


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

0

精彩评论

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

关注公众号