.Net's Server.HTMLEncode() is the very helpful function that takes an HTML string and replaces special characters with their entity equivalents - "<" becomes < ; and so forth.
.Net的Server.HTMLEncode()是一个非常有用的函数,它接受一个HTML字符串并用它们的实体等价替换特殊字符 - “<”变为<等等。
Is there a (built-in) function that does the reverse? There doesn't seem to be, and I am incredulous. While I could certainly write my own (and have in the past) Server.HTMLEncode has all kinds of cool handling for different string encodings and high-level unicode characters that I would really not have crash my hand-rolled decoder in a year's time.
是否有(内置)功能可以反过来?似乎没有,我不相信。虽然我当然可以编写自己的(并且在过去)Server.HTMLEncode对不同的字符串编码和高级unicode字符有各种各样的酷处理,我真的不会在一年的时间内崩溃我的手动解码器。
What do other people do when they need the plain HTML back?
当其他人需要简单的HTML后,他们会怎么做?
Update: To answer the first batch of questions, I present the MSDN article on the Server object, which has Encode but no Decode... I'm as amazed as anyone.
更新:为了回答第一批问题,我在服务器对象上提供MSDN文章,该文章具有Encode但没有解码...我对任何人都感到惊讶。
Update2: as several alert readers have pointed out, the docs I was looking at were for classic ASP, not ASP.Net. Thanks guys, that's an important MSDN safety tip.
Update2:正如几位警报读者指出的那样,我所看到的文档是针对经典ASP,而不是ASP.Net。谢谢大家,这是一个重要的MSDN安全提示。
5 个解决方案
#1
You're looking at the wrong docs. Check this out:
你正在查看错误的文档。看一下这个:
http://msdn.microsoft.com/en-us/library/system.web.httpserverutility_methods.aspx http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.htmlencode.aspx http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.htmldecode.aspx
http://msdn.microsoft.com/en-us/library/system.web.httpserverutility_methods.aspx http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.htmlencode.aspx http: //msdn.microsoft.com/en-us/library/system.web.httpserverutility.htmldecode.aspx
#2
Server.HtmlDecode ....
#3
You didn't see a HtmlDecode in the same place you found the HtmlEncode?
您没有在找到HtmlEncode的同一个地方看到HtmlDecode?
#4
HttpServerUtility.HtmlDecode
#5
Ah, MSDN, I love you.
啊,MSDN,我爱你。
There IS a Server.HTMLDecode() method, the documentation for the server object just doesn't mention that it exists.
有一个Server.HTMLDecode()方法,服务器对象的文档只是没有提到它存在。
Thanks, everybody!
#1
You're looking at the wrong docs. Check this out:
你正在查看错误的文档。看一下这个:
http://msdn.microsoft.com/en-us/library/system.web.httpserverutility_methods.aspx http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.htmlencode.aspx http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.htmldecode.aspx
http://msdn.microsoft.com/en-us/library/system.web.httpserverutility_methods.aspx http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.htmlencode.aspx http: //msdn.microsoft.com/en-us/library/system.web.httpserverutility.htmldecode.aspx
#2
Server.HtmlDecode ....
#3
You didn't see a HtmlDecode in the same place you found the HtmlEncode?
您没有在找到HtmlEncode的同一个地方看到HtmlDecode?
#4
HttpServerUtility.HtmlDecode
#5
Ah, MSDN, I love you.
啊,MSDN,我爱你。
There IS a Server.HTMLDecode() method, the documentation for the server object just doesn't mention that it exists.
有一个Server.HTMLDecode()方法,服务器对象的文档只是没有提到它存在。
Thanks, everybody!