如何停止Server.HtmlEncode对UTF8字符进行编码?

发布于 2024-12-02 19:06:47 字数 549 浏览 0 评论 0原文

如何停止 Server.HtmlEncode 对 UTF8 字符进行编码?我将代码页设置为 UTF8 但没有帮助

这是我的测试用例:

<%@CODEPAGE=65001%>
<%
Response.CodePage = 65001
Response.CharSet = "utf-8"
%>
<%=Server.HtmlEncode("русский stuff <b>bold stuff</b>")%>

它通常应该输出这个:

русский stuff &lt;b&gt;bold stuff&lt;/b&gt;

但输出是:

&#1088;&#1091;&#1089;&#1089;&#1082;&#1080;&#1081; stuff &lt;b&gt;bold stuff&lt;/b&gt;

How can I stop Server.HtmlEncode to encode UTF8 characters? I set the codepage to UTF8 but didn't help

Here is my test case:

<%@CODEPAGE=65001%>
<%
Response.CodePage = 65001
Response.CharSet = "utf-8"
%>
<%=Server.HtmlEncode("русский stuff <b>bold stuff</b>")%>

It should normally output this:

русский stuff <b>bold stuff</b>

but the output is:

русский stuff <b>bold stuff</b>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

微暖i 2024-12-09 19:06:47

Server.HtmlEncode 方法转义 >,<,&," 字符以及任何代码大于或等于 0x80 的 ascii 代码字符。
您可以过滤哪个字符将会被逃脱。
有通用字符将被编码在模式中。
如果您愿意,您也可以添加一些其他字符。

Private Function cb_Escape(ByVal a, ByVal b, ByVal c, ByVal d)
    cb_Escape = Server.HTMLEncode(b)
End Function

Private Function HTMLEncode2(ByVal sHTML)
    Dim oReg
    Set oReg = New RegExp
        oReg.Global = True
        oReg.Pattern = "([<>""&]+)"
        HTMLEncode2 = oReg.Replace(sHTML, GetRef("cb_Escape"))
    Set oReg = Nothing
End Function

Response.Write HTMLEncode2("русский stuff <b>bold stuff</b>")

Server.HtmlEncode method escapes >,<,&," chars and any ascii code character whose code is greater than or equal to 0x80.
You can filter which character will be escaped.
There are generic characters will be encoded in pattern.
If you prefer, you can add some other chars too.

Private Function cb_Escape(ByVal a, ByVal b, ByVal c, ByVal d)
    cb_Escape = Server.HTMLEncode(b)
End Function

Private Function HTMLEncode2(ByVal sHTML)
    Dim oReg
    Set oReg = New RegExp
        oReg.Global = True
        oReg.Pattern = "([<>""&]+)"
        HTMLEncode2 = oReg.Replace(sHTML, GetRef("cb_Escape"))
    Set oReg = Nothing
End Function

Response.Write HTMLEncode2("русский stuff <b>bold stuff</b>")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文