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

2

7

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

Lactam answered 29/2, 2012 at 16:4 Comment(0)
P
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).

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.

Permanence answered 29/2, 2012 at 22:2 Comment(1)
For those who might have arrived here looking to set CharSet globally for an ASP.NET application, this is possible. See the <globalization> element in Web.config. Also, in ASP.NET, CodePage 65001 is the default. (CodePage governs how the ASP.NET source code is processed on the server. CharSet governs what character encoding (e.g. UTF-8) is returned to the client.)Nela
D
6

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

Didi answered 29/2, 2012 at 16:43 Comment(1)
so anyway I should amend every page in my site?Gardia
P
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).

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.

Permanence answered 29/2, 2012 at 22:2 Comment(1)
For those who might have arrived here looking to set CharSet globally for an ASP.NET application, this is possible. See the <globalization> element in Web.config. Also, in ASP.NET, CodePage 65001 is the default. (CodePage governs how the ASP.NET source code is processed on the server. CharSet governs what character encoding (e.g. UTF-8) is returned to the client.)Nela

© 2022 - 2024 — McMap. All rights reserved.