如何更改标题为特定类型的IIS / MVC送达文件 [英] How to change headers for specific types of files served in IIS / MVC
问题描述
我实现了超过3G造成02 COM pression问题该问题的补丁。
I am implementing a fix for the problem caused by 02 compression issues over 3G.
<一个href=\"http://stackoverflow.com/questions/3282373/web-site-exhibits-javascript-error-on-ipad-iphone-under-3g-but-not-under-wifi\">Web现场展品在3G iPad / iPhone的JavaScript错误而不是下的WiFi
最好的解决方案似乎是的http:// stuartroebuck.blogspot.com/2010/08/official-way-to-bypassing-data.html 这基本上是添加标题缓存控制:无转换
在IIS,但是我想这仅适用于特定的文件类型。什么是做到这一点的最简单的方法?
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?
推荐答案
这是我写的HttpModule的最佳解决方案。我写了个例子。
您可以检查MIME类型特定的文件类型。
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");
}
}
你也需要添加的web.config
Also you have to add it web.config
<configuration>
<system.web>
<httpModules>
<add name="AddHeaderModule" type="your.namespace.AddHeaderModule" />
</httpModules>
</system.web>
</configuration>
这篇关于如何更改标题为特定类型的IIS / MVC送达文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!