WebResource.axd and HTTP headers

Our site has moved from .NET 1.1 to .NET 3.5, and in the process of updating our third-party server controls. One of these packages uses javascript provided through WebResource.axd. They are included as regular tags <script src="" />.

However, while watching the traffic, I see that these javascript files encounter headers that prevent client side caching. And we say a lot of javascript. The headings 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 without creating an HttpModule? Is this something I can blame the control provider for? <brandish weapon="blameGun" />

Thank,

Baron

+2
source share
3 answers

You can try:

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

Other types are HttpCacheabilitydescribed here:

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

Edit:

You can throw this into your Global.asaxfile instead of a module:

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

This can happen if your website is deployed using the <compilation debug="true">one installed in its web.config. In this case, caching is disabled to simplify debugging JavaScript files used as embedded resources. The solution is to simply set the debug attribute of the compilation tag to false. More information can be found in this excellent blog post.

+5

Thank you for your responses. It turned out that we already had an HttpModule, which I did not want to write in place, and this was the source of the problem.

0
source

All Articles