IIS Server - How to set content-type header for ASP/HTML pages only ?

This is Interesting: Free IT Magazines  
Home > Archive > IIS Server > February 2004 > How to set content-type header for ASP/HTML pages only ?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author How to set content-type header for ASP/HTML pages only ?
Alan Silver

2004-02-16, 3:34 am

Hello,

I would like to set the content-type HTTP header for Content-Type. I
tried adding the header :-

Content-Type: text/html; charset=ISO-8859-1

as recommended by the W3C, but this sends this header for *all* files
served, not just ASP and HTML. For example, it sends the header for CSS
files, which causes the validators to choke.

Is there any way to set the Content-Type specific to file type ? I
searched Google, but didn't find anything on this. It seems strange to
be able to set a global Content-Type, but not be able to associate it
with a file type.

TIA

P.S. I am using IIS4 on NT4 Server if it makes any difference.

--
Alan Silver

David Wang [Msft]

2004-02-16, 10:35 am

The right way to do this association is with a MIME-Type (IIS can configure
this on a per-URL level, meaning you can even make SOME ASP pages return
custom values but not others, depending on URL scope), which allows you to
set the value of the Content-Type header on a per-extension basis. This
requires restarting IIS for it to take effect.

What you were doing was setting headers that IIS sends on all requests,
which is valid for other uses, just not for Content-Type.

--
//David
IIS
This posting is provided "AS IS" with no warranties, and confers no rights.
//
"Alan Silver" <alan-silver@nospam.thanx> wrote in message
news:TwL$pdLdJPMAFwLh@nospamthankyou.spam...
Hello,

I would like to set the content-type HTTP header for Content-Type. I
tried adding the header :-

Content-Type: text/html; charset=ISO-8859-1

as recommended by the W3C, but this sends this header for *all* files
served, not just ASP and HTML. For example, it sends the header for CSS
files, which causes the validators to choke.

Is there any way to set the Content-Type specific to file type ? I
searched Google, but didn't find anything on this. It seems strange to
be able to set a global Content-Type, but not be able to associate it
with a file type.

TIA

P.S. I am using IIS4 on NT4 Server if it makes any difference.

--
Alan Silver



Alan Silver

2004-02-17, 4:35 am

In article <ebV#DPO9DHA.2404@TK2MSFTNGP11.phx.gbl>, "David Wang [Msft]"
<someone@online.microsoft.com> writes
>The right way to do this association is with a MIME-Type (IIS can configure
>this on a per-URL level, meaning you can even make SOME ASP pages return
>custom values but not others, depending on URL scope), which allows you to
>set the value of the Content-Type header on a per-extension basis. This
>requires restarting IIS for it to take effect.
>
>What you were doing was setting headers that IIS sends on all requests,
>which is valid for other uses, just not for Content-Type.


Thanx for the reply.

I thought that MIME types were only for setting the content type. I want
to set the character encoding. I was doing it via a Content-Type header
as that was a) the way suggested by the W3C and b) 'cos I didn't know
any other way to do it for the whole server.

Do you know how to set the character encoding for all ASP/HTML pages
served ? TIA

>"Alan Silver" <alan-silver@nospam.thanx> wrote in message
>news:TwL$pdLdJPMAFwLh@nospamthankyou.spam...
>Hello,
>
>I would like to set the content-type HTTP header for Content-Type. I
>tried adding the header :-
>
>Content-Type: text/html; charset=ISO-8859-1
>
>as recommended by the W3C, but this sends this header for *all* files
>served, not just ASP and HTML. For example, it sends the header for CSS
>files, which causes the validators to choke.
>
>Is there any way to set the Content-Type specific to file type ? I
>searched Google, but didn't find anything on this. It seems strange to
>be able to set a global Content-Type, but not be able to associate it
>with a file type.
>
>TIA
>
>P.S. I am using IIS4 on NT4 Server if it makes any difference.
>


--
Alan Silver

David Wang [Msft]

2004-02-18, 8:35 am

Character encoding, per the HTTP 1.1 spec on W3C, is a part of Content-Type
(what is transmitted over the wire is
Content-Encoding(Content-Type(data)) ). IIS supports this feature via MIME
Map, which sets Content-Type on a per-extension basis (including "all"
extensions).

Thus, you should configuration the MIME Map setting on IIS (it's right below
where you set Custom HTTP response headers). It can be set to take effect
globally unless you override it with another MIME Map setting. You will
have to restart IIS for the changes to take effect (you don't have to, but
I'm having you to it to be safe for other reasons).

If you do not wish to use built in functionality exposed via the UI, feel
free to write your own custom ISAPI Filter to implement your desired
functionality.

BTW: I just set the MIME Map for .html to "text/html; charset=ISO-8859-1" at
the per website level, and instantly, only requests to .html on that website
returned "Content-Type: text/html; charset=ISO-8859-1". It seems like it's
what you were looking for.

--
//David
IIS
This posting is provided "AS IS" with no warranties, and confers no rights.
//
"Alan Silver" <alan-silver@nospam.thanx> wrote in message
news:sZ+gzgEJJlMAFwvV@nospamthankyou.spam...
In article <ebV#DPO9DHA.2404@TK2MSFTNGP11.phx.gbl>, "David Wang [Msft]"
<someone@online.microsoft.com> writes
>The right way to do this association is with a MIME-Type (IIS can configure
>this on a per-URL level, meaning you can even make SOME ASP pages return
>custom values but not others, depending on URL scope), which allows you to
>set the value of the Content-Type header on a per-extension basis. This
>requires restarting IIS for it to take effect.
>
>What you were doing was setting headers that IIS sends on all requests,
>which is valid for other uses, just not for Content-Type.


Thanx for the reply.

I thought that MIME types were only for setting the content type. I want
to set the character encoding. I was doing it via a Content-Type header
as that was a) the way suggested by the W3C and b) 'cos I didn't know
any other way to do it for the whole server.

Do you know how to set the character encoding for all ASP/HTML pages
served ? TIA

>"Alan Silver" <alan-silver@nospam.thanx> wrote in message
>news:TwL$pdLdJPMAFwLh@nospamthankyou.spam...
>Hello,
>
>I would like to set the content-type HTTP header for Content-Type. I
>tried adding the header :-
>
>Content-Type: text/html; charset=ISO-8859-1
>
>as recommended by the W3C, but this sends this header for *all* files
>served, not just ASP and HTML. For example, it sends the header for CSS
>files, which causes the validators to choke.
>
>Is there any way to set the Content-Type specific to file type ? I
>searched Google, but didn't find anything on this. It seems strange to
>be able to set a global Content-Type, but not be able to associate it
>with a file type.
>
>TIA
>
>P.S. I am using IIS4 on NT4 Server if it makes any difference.
>


--
Alan Silver


Alan Silver

2004-02-19, 1:35 am

In article <eiCANjm9DHA.632@TK2MSFTNGP12.phx.gbl>, "David Wang [Msft]"
<someone@online.microsoft.com> writes
>Character encoding, per the HTTP 1.1 spec on W3C, is a part of Content-Type
>(what is transmitted over the wire is
>Content-Encoding(Content-Type(data)) ). IIS supports this feature via MIME
>Map, which sets Content-Type on a per-extension basis (including "all"
>extensions).
>
>Thus, you should configuration the MIME Map setting on IIS (it's right below
>where you set Custom HTTP response headers). It can be set to take effect
>globally unless you override it with another MIME Map setting. You will
>have to restart IIS for the changes to take effect (you don't have to, but
>I'm having you to it to be safe for other reasons).
>
>If you do not wish to use built in functionality exposed via the UI, feel
>free to write your own custom ISAPI Filter to implement your desired
>functionality.
>
>BTW: I just set the MIME Map for .html to "text/html; charset=ISO-8859-1" at
>the per website level, and instantly, only requests to .html on that website
>returned "Content-Type: text/html; charset=ISO-8859-1". It seems like it's
>what you were looking for.


David,

Thanx very much, that explains it fine. I just tried it on a test server
here and it seems to be OK. I didn't realise that you could add the
encoding in with the content type.

Just out of interest, why do you say the server should be restarted "for
other reasons" ? I don't really want to restart the production server
more than I have to as it is accessed 24x7.

Thanx again


>--
>//David
>IIS
>This posting is provided "AS IS" with no warranties, and confers no rights.
>//
>"Alan Silver" <alan-silver@nospam.thanx> wrote in message
>news:sZ+gzgEJJlMAFwvV@nospamthankyou.spam...
>In article <ebV#DPO9DHA.2404@TK2MSFTNGP11.phx.gbl>, "David Wang [Msft]"
><someone@online.microsoft.com> writes
>
>Thanx for the reply.
>
>I thought that MIME types were only for setting the content type. I want
>to set the character encoding. I was doing it via a Content-Type header
>as that was a) the way suggested by the W3C and b) 'cos I didn't know
>any other way to do it for the whole server.
>
>Do you know how to set the character encoding for all ASP/HTML pages
>served ? TIA
>
>


--
Alan Silver

David Wang [Msft]

2004-02-20, 3:35 am

MIME Type can be set on a per-URL basis all the way to global.

Global MIME Type changes require IIS Web Server restart (about a 5-10 second
process) to take effect. Other per-URL settings take effect immediately.

Reason I want a restart of IIS is because when you change IIS configuration
while running, it is *possible* that it is NEVER saved -- so if your server
crashes, upon restart, you will find all your prior settings just missing
(it's like making changes in Word, never saving, and then Word crashes --
you lose all the non-saved changes).

Restarting IIS forces a flush of the in-memory configuration changes to disk
(in effect, a "save"), and if anything crashes... you'll know sooner rather
than later who the culprit is. You can trigger the flush without restarting
IIS by writing a script on the commandline which uses IIS's administration
API, but usually, it's easier for people to understand restarting IIS
instead of telling them how to write scripts.

--
//David
IIS
This posting is provided "AS IS" with no warranties, and confers no rights.
//
"Alan Silver" <alan-silver@nospam.thanx> wrote in message
news:Yg39tWDoANNAFwCs@nospamthankyou.spam...
In article <eiCANjm9DHA.632@TK2MSFTNGP12.phx.gbl>, "David Wang [Msft]"
<someone@online.microsoft.com> writes
>Character encoding, per the HTTP 1.1 spec on W3C, is a part of Content-Type
>(what is transmitted over the wire is
>Content-Encoding(Content-Type(data)) ). IIS supports this feature via MIME
>Map, which sets Content-Type on a per-extension basis (including "all"
>extensions).
>
>Thus, you should configuration the MIME Map setting on IIS (it's right

below
>where you set Custom HTTP response headers). It can be set to take effect
>globally unless you override it with another MIME Map setting. You will
>have to restart IIS for the changes to take effect (you don't have to, but
>I'm having you to it to be safe for other reasons).
>
>If you do not wish to use built in functionality exposed via the UI, feel
>free to write your own custom ISAPI Filter to implement your desired
>functionality.
>
>BTW: I just set the MIME Map for .html to "text/html; charset=ISO-8859-1"

at
>the per website level, and instantly, only requests to .html on that

website
>returned "Content-Type: text/html; charset=ISO-8859-1". It seems like

it's
>what you were looking for.


David,

Thanx very much, that explains it fine. I just tried it on a test server
here and it seems to be OK. I didn't realise that you could add the
encoding in with the content type.

Just out of interest, why do you say the server should be restarted "for
other reasons" ? I don't really want to restart the production server
more than I have to as it is accessed 24x7.

Thanx again


>--
>//David
>IIS
>This posting is provided "AS IS" with no warranties, and confers no rights.
>//
>"Alan Silver" <alan-silver@nospam.thanx> wrote in message
>news:sZ+gzgEJJlMAFwvV@nospamthankyou.spam...
>In article <ebV#DPO9DHA.2404@TK2MSFTNGP11.phx.gbl>, "David Wang [Msft]"
><someone@online.microsoft.com> writes
configure[color=blue]
>
>Thanx for the reply.
>
>I thought that MIME types were only for setting the content type. I want
>to set the character encoding. I was doing it via a Content-Type header
>as that was a) the way suggested by the W3C and b) 'cos I didn't know
>any other way to do it for the whole server.
>
>Do you know how to set the character encoding for all ASP/HTML pages
>served ? TIA
>
>


--
Alan Silver


Alan Silver

2004-02-23, 1:34 am

In article <eWqtZH99DHA.2168@TK2MSFTNGP12.phx.gbl>, "David Wang [Msft]"
<someone@online.microsoft.com> writes
>Reason I want a restart of IIS is because when you change IIS
>configuration while running, it is *possible* that it is NEVER saved --
>so if your server crashes, upon restart, you will find all your prior
>settings just missing (it's like making changes in Word, never saving,
>and then Word crashes -- you lose all the non-saved changes).


Fine, I can see that. I was more concerned that you knew of some serious
side-effect of making changes and not restarting the server. This is
just an inconvenience and can easily be tackled. More to the point, I
can make the change and rely on the settings being changed next time the
system is restarted, I don't have to take down a production server
specially for this change.

Thanx for the reply.

--
Alan Silver

David Wang [Msft]

2004-02-24, 5:34 am

Prior to IIS6, unless you make sure the metabase is flushed from memory to
disk, your changes made via UI are vulnerable to being lost when the system
restarts. Period. It depends on whether anything crashes inetinfo.exe
prior to it stopping -- if you have everything running in High Isolation, no
inproc ISAPI Extensions, and no ISAPI Filters it's probably a good guess
that inetinfo.exe won't crash -- but the probability to crash increase in
all other cases.

You just have to be aware that IF this happens to you, that you need to
re-apply all your lost changes, assuming you knew what they all are. If you
are comfortable with that, great.

--
//David
IIS
This posting is provided "AS IS" with no warranties, and confers no rights.
//
"Alan Silver" <alan-silver@nospam.thanx> wrote in message
news:aAZ9FxFerMOAFwpf@nospamthankyou.spam...
In article <eWqtZH99DHA.2168@TK2MSFTNGP12.phx.gbl>, "David Wang [Msft]"
<someone@online.microsoft.com> writes
>Reason I want a restart of IIS is because when you change IIS
>configuration while running, it is *possible* that it is NEVER saved --
>so if your server crashes, upon restart, you will find all your prior
>settings just missing (it's like making changes in Word, never saving,
>and then Word crashes -- you lose all the non-saved changes).


Fine, I can see that. I was more concerned that you knew of some serious
side-effect of making changes and not restarting the server. This is
just an inconvenience and can easily be tackled. More to the point, I
can make the change and rely on the settings being changed next time the
system is restarted, I don't have to take down a production server
specially for this change.

Thanx for the reply.

--
Alan Silver


Alan Silver

2004-02-24, 6:34 am

In article <#jA3uaw#DHA.3184@TK2MSFTNGP09.phx.gbl>, "David Wang [Msft]"
<someone@online.microsoft.com> writes
>You just have to be aware that IF this happens to you, that you need to
>re-apply all your lost changes, assuming you knew what they all are. If
>you are comfortable with that, great.


Understood thanx.

--
Alan Silver

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com