简体   繁体   中英

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

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM