vb.net 一个具有 utf-8 编码的 aspx 页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33283697/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 19:31:33  来源:igfitidea点击:

One aspx page to have utf-8 encoding

c#asp.netvb.netutf-8

提问by Linta Sheelkumar

What should I do to change one aspx page to have utf-8 encoding?

我应该怎么做才能将一个 aspx 页面更改为 utf-8 编码?

my web.config has the following code:

我的 web.config 有以下代码:

<system.web>
  <globalization
     requestEncoding="utf-8"
     responseEncoding="utf-8"/>
</system.web>

Tried this:

试过这个:

meta http-equiv="Content-Type" content="text/html; charset=UTF-8" 

doesn't work.

不起作用。

回答by Salah Akbari

Try this;

尝试这个;

<configuration>
 <system.web>
  <globalization
    fileEncoding="utf-8" 
    requestEncoding="utf-8" 
    responseEncoding="utf-8"
    culture="en-US"
    uiCulture="de-DE"
   />
 </system.web>
</configuration>

To set the encoding for an individual page, set the RequestEncodingand ResponseEncodingattributes of the @ Pagedirective:

要为单个页面设置编码,请设置指令的RequestEncodingResponseEncoding属性@ Page

<%@ Page RequestEncoding="utf-8" ResponseEncoding="utf-8" %>

Or you can use locationlike this:

或者你可以这样使用location

<location path="home.aspx">
    <system.web>
        <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
    </system.web>
</location>

Read more: How to: Select an Encoding for ASP.NET Web Page Globalization.

阅读更多:如何:为 ASP.NET 网页全球化选择编码。

回答by masinger

Try to insert

尝试插入

Response.ContentEncoding = System.Text.Encoding.UTF8;

In your Page_Loadif you want to do it dynamically.

在你的Page_Load,如果你要动态地做到这一点。