IIS 6 - Classic ASP - Set *.asp response header's content-type to “text/html;charset=UTF-8”

半世苍凉 提交于 2021-02-04 17:40:53

问题


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.

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.

Thanks! -K


回答1:


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).

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.

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.




回答2:


EDIT 1: Ive tested this with IE9's developer tools (network tab),

<%
response.ContentType = "text/html;charset=UTF-8"
%>

Results in a HTML header for Content-Type of:

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.

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

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).



来源:https://stackoverflow.com/questions/9502490/iis-6-classic-asp-set-asp-response-headers-content-type-to-text-htmlcha

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!