How do I can set *.asp
files (Classic ASP) in a Web Site under IIS to have Response Header's Content-Type set to text/html;charset=UTF-8
? Right now, the files are served as Content-Type=text/html
.
如何设置*。在IIS下的Web站点中,将响应头的内容类型设置为文本/html;charset=UTF-8?现在,这些文件被用作内容类型=文本/html。
An alternate approach is to add <% Response.Charset = "UTF-8" %>
to every single page, but I wonder if there's a way to do it globally.
另一种方法是添加<% Response。Charset = "UTF-8" %>到每一页,但我想知道是否有办法在全球范围内做到这一点。
Thanks! -K
谢谢!- k
2 个解决方案
#1
3
There is no means to globally specify the CharSet
for an application.
没有方法全局指定应用程序的字符集。
There is actually more to it than just telling the client its getting UTF-8. You also need to ensure the response object is configured to the 65001 codepage. This at least can be set globally using the AspCodePage
metabase value at the application level (or directly in the ASP feature in IIS7 manager).
实际上,它不仅仅是告诉客户它的UTF-8。您还需要确保将响应对象配置为65001代码页。至少可以使用应用程序级别的AspCodePage metabase值(或者直接在IIS7 manager中的ASP特性中)全局设置这个值。
However my preference with this sort of thing is to avoid depending on the server to be configured correctly. Each page sets its codepage (either with the @CODEPAGE
directive or with Response.Codepage
) and its CharSet
.
然而,我对这类事情的偏好是避免依赖于要正确配置的服务器。每个页面都设置它的代码页(要么使用@CODEPAGE指令,要么使用Response.Codepage)及其字符集。
I have two reasons for this approach. One is that ultimately the CharSet/Codepage is choice made at the time of creating and saving the file. The other is that when depolying/copying the site the less you have to remember to configure the better.
我这么做有两个原因。一种是,CharSet/Codepage最终是在创建和保存文件时作出的选择。另一种是,当对站点进行反极化/复制时,您需要记住的配置越少越好。
#2
5
EDIT 1: Ive tested this with IE9's developer tools (network tab),
编辑1:我用IE9的开发者工具(网络标签)测试过这个,
<%
response.ContentType = "text/html;charset=UTF-8"
%>
Results in a HTML header for Content-Type of:
结果为内容类型的HTML头:
text/html;charset=UTF-8
Whereas, setting it at the MIME level on IIS7 does not - i'll update my answer when i figure out why.
然而,在IIS7上将它设置为MIME级别并不会——我将在找出原因时更新我的答案。
EDIT 2: I cant get the global MIME approach to work on my test rig - sorry! There are hints of this online: http://forums.iis.net/p/1166956/1941076.aspx#1941076
编辑2:我不能让全局MIME方法在我的测试平台上工作-对不起!网上有一些提示:http://forums.iis.net/p/1166956/1941076.aspx#1941076
I'm guessing you'll just have to pop the response.ContentType = "text/html;charset=UTF-8"
in an <!-- #include file="..\includes\common.asp" -->
type include (or similar).
我猜你只需要弹出回应。内容类型= "text/html;charset=UTF-8" 类型包括(或类似)。
#1
3
There is no means to globally specify the CharSet
for an application.
没有方法全局指定应用程序的字符集。
There is actually more to it than just telling the client its getting UTF-8. You also need to ensure the response object is configured to the 65001 codepage. This at least can be set globally using the AspCodePage
metabase value at the application level (or directly in the ASP feature in IIS7 manager).
实际上,它不仅仅是告诉客户它的UTF-8。您还需要确保将响应对象配置为65001代码页。至少可以使用应用程序级别的AspCodePage metabase值(或者直接在IIS7 manager中的ASP特性中)全局设置这个值。
However my preference with this sort of thing is to avoid depending on the server to be configured correctly. Each page sets its codepage (either with the @CODEPAGE
directive or with Response.Codepage
) and its CharSet
.
然而,我对这类事情的偏好是避免依赖于要正确配置的服务器。每个页面都设置它的代码页(要么使用@CODEPAGE指令,要么使用Response.Codepage)及其字符集。
I have two reasons for this approach. One is that ultimately the CharSet/Codepage is choice made at the time of creating and saving the file. The other is that when depolying/copying the site the less you have to remember to configure the better.
我这么做有两个原因。一种是,CharSet/Codepage最终是在创建和保存文件时作出的选择。另一种是,当对站点进行反极化/复制时,您需要记住的配置越少越好。
#2
5
EDIT 1: Ive tested this with IE9's developer tools (network tab),
编辑1:我用IE9的开发者工具(网络标签)测试过这个,
<%
response.ContentType = "text/html;charset=UTF-8"
%>
Results in a HTML header for Content-Type of:
结果为内容类型的HTML头:
text/html;charset=UTF-8
Whereas, setting it at the MIME level on IIS7 does not - i'll update my answer when i figure out why.
然而,在IIS7上将它设置为MIME级别并不会——我将在找出原因时更新我的答案。
EDIT 2: I cant get the global MIME approach to work on my test rig - sorry! There are hints of this online: http://forums.iis.net/p/1166956/1941076.aspx#1941076
编辑2:我不能让全局MIME方法在我的测试平台上工作-对不起!网上有一些提示:http://forums.iis.net/p/1166956/1941076.aspx#1941076
I'm guessing you'll just have to pop the response.ContentType = "text/html;charset=UTF-8"
in an <!-- #include file="..\includes\common.asp" -->
type include (or similar).
我猜你只需要弹出回应。内容类型= "text/html;charset=UTF-8" 类型包括(或类似)。