Changing Content-Type Header of static files in IIS 6 with out access to IIS
I'm trying to change the content type of static files severed by IIS6 on a shared 开发者_运维技巧host where I don't have access to IIS I tried
<system.webServer>
<staticContent>
<remove fileExtension=".manifest" />
<mimeMap fileExtension=".manifest" mimeType="text/cache-manifest" />
</staticContent>
</system.webServer>
In my web.config but that appears to only work with IIS7 In case there is any doubt after that sample I am trying to change all static files served with the extension .manifest to have the mimeType text/cache-manifest
Thanks.
If you are happy changing the MIME types for the entire web server AND you can run ASP.NET code then this snippet will add the MIME types for you in IIS 6 (the code is from http://forums.silverlight.net/p/138545/449294.aspx):
try
{
string ext = ".xap";
string mime = "application/x-silverlight-app";
using (DirectoryEntry mimeMap = new DirectoryEntry("IIS://localhost/MimeMap"))
{
bool found = false;
foreach (MimeMap m in mimeMap.Properties["MimeMap"])
{
if (m.Extension == ext)
{
// found existing, update
m.MimeType = mime;
found = true;
}
}
// not found, create new
if (!found)
{
mimeMap.Properties["MimeMap"].Add(new MimeMapClass { Extension = ext, MimeType = mime });
}
// commit changes
mimeMap.CommitChanges();
}
}
catch (Exception e)
{
// Log exception to event viewer
// Show message stating to configure mime type manually
}
I found out pretty quickly that you can only add one MIME type at a time, if you want add more than that you will have to instantiate a new directory server instance for every MIME type you add..
Hope that helps...
精彩评论