【发布时间】:2011-07-17 00:31:33
【问题描述】:
我正在尝试在我的站点中的所有 ashx 文件上启用输出缓存。我试图阻止服务器在每个请求上生成文件——而不是试图告诉浏览器缓存文件。
我已将我的 ashx 文件提炼成以下简单代码:
public class DefaultStyles : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/css";
StringBuilder styleSheet = new StringBuilder();
styleSheet.AppendLine(string.Format("/* Generated: {0}, {1} */", DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString()));
context.Response.Write(styleSheet.ToString());
}
}
在我的 web.config 文件中,我有这个:
<system.webserver>
<caching enabled="true">
<profiles>
<add extension=".ashx" policy="CacheForTimePeriod" duration="00:01:00" />
</profiles>
</caching>
</system.webserver>
不过,我对 ashx 文件的每个请求都会生成一个包含当前日期和时间的新版本。
我做错了什么?
谢谢。
【问题讨论】:
-
您使用的是什么版本的网络服务器?我刚刚对其进行了测试,它在 IIS 7.5 上运行良好。您能否也显示处理程序配置设置?
-
你明白了,我在 VS 开发者网络服务器中进行测试。一旦我在我们的 IIS 7 服务器上部署了上面的简单示例,它就可以使用上面的代码按预期工作。应该注意的是,这在我们的 IIS 6 服务器上不起作用。我没有意识到这是一项仅在 IIS 7 中可用的新功能
标签: c# asp.net outputcache ashx