WebResource.axd 和 HTTP 标头

发布于 2024-07-16 21:48:40 字数 527 浏览 6 评论 0 原文

我们的网站刚刚从 .NET 1.1 迁移到 .NET 3.5,并在此过程中更新了我们的第 3 方服务器控件。 这些包之一使用通过 WebResource.axd 提供的 javascript。 这些内容作为正常的

然而,通过观察流量,我发现这些 javascript 文件遇到了阻止客户端缓存的标头。 我们谈论了很多 JavaScript。 有问题的标头:

Cache-control: no-cache, no-store
pragma: no-cache
Expires: -1

这些标头可以在 .NET 中的某个位置进行配置吗? 我可以在构建 HttpModule 的情况下拦截这些请求吗? 这是我可以责怪控制供应商的事情吗? >

谢谢,

男爵

Our site just moved from .NET 1.1 to .NET 3.5, and in the process updated our 3rd party server controls. One of these packages uses javascript provided via WebResource.axd. These are included as normal <script src="" /> tags.

Watching the traffic, however, I see that these javascript files are coming across with headers that prevent client-side caching. And we're talking a lot of javascript. The headers in question:

Cache-control: no-cache, no-store
pragma: no-cache
Expires: -1

Are these headers configurable in .NET somewhere? Can I intercept these requests short of building an HttpModule? Is this something I can blame the control vendor for? <brandish weapon="blameGun" />

Thanks,

Baron

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

前事休说 2024-07-23 21:48:40

您可以尝试:

HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public);

其他类型的 HttpCacheability 记录在此处:

http://msdn.microsoft.com/en-us/library/system.web.httpcacheability.aspx

编辑:

您可以将其放入 Global.asax 文件而不是模块:

void Application_AuthorizeRequest(object sender, EventArgs e)
{
    if (Request.Path.IndexOf("WebResource.axd") > -1)
    {
        Response.Cache.SetCacheability(HttpCacheability.Public);
    }
}

You could try:

HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public);

The other types of HttpCacheability are documented here:

http://msdn.microsoft.com/en-us/library/system.web.httpcacheability.aspx

Edit:

You can throw this in your Global.asax file instead of a module:

void Application_AuthorizeRequest(object sender, EventArgs e)
{
    if (Request.Path.IndexOf("WebResource.axd") > -1)
    {
        Response.Cache.SetCacheability(HttpCacheability.Public);
    }
}
剩余の解释 2024-07-23 21:48:40

如果您的网站部署时在其 web.config 中设置了 ,则可能会发生这种情况。 在这种情况下,缓存被禁用,以便更轻松地调试用作嵌入式资源的 JavaScript 文件。 解决办法就是简单地将compilation标签的debug属性设置为false即可。 更多信息可以在这篇优秀博客文章中找到。

This may occur if your web site is deployed with <compilation debug="true"> set in its web.config. Caching is disabled in this case for easier debugging of JavaScript files served as embedded resources. The solution is to simply set the debug attribute of the compilation tag to false. More info can be found in this excellent blog post.

属性 2024-07-23 21:48:40

感谢您的回复。 事实证明我们已经有了我不想写的 HttpModule,这就是问题的根源。

Thanks for your responses. It turned out we already had the HttpModule that I didn't want to write in place, and it was the source of the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文