问题
I am implementing a fix for the problem caused by 02 compression issues over 3G.
Web site exhibits JavaScript error on iPad / iPhone under 3G but not under WiFi
The best solution seems to be http://stuartroebuck.blogspot.com/2010/08/official-way-to-bypassing-data.html which is basically to add the header Cache-Control: no-transform in IIS, however I would like to apply this only to specific file types. What is the easiest way to do this?
回答1:
It is the best solution for me to write a HttpModule. I wrote an example for you. You can check mime type for specific file types.
public class AddHeaderModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.EndRequest += OnEndRequest;
}
void OnEndRequest(object sender, System.EventArgs e)
{
if(HttpContext.Current.Response.ContentType == "image/jpeg")
HttpContext.Current.Response.Headers.AddHeader("Cache-Control", "no-transform");
}
}
Also you have to add it web.config
<configuration>
<system.web>
<httpModules>
<add name="AddHeaderModule" type="your.namespace.AddHeaderModule" />
</httpModules>
</system.web>
</configuration>
来源:https://stackoverflow.com/questions/8230001/how-to-change-headers-for-specific-types-of-files-served-in-iis-mvc