开发者

Output (server-side) caching of ashx files

开发者 https://www.devze.com 2023-02-17 12:37 出处:网络
I am trying to enable output caching on all ashx files in my site.I\'m trying to keep the server from generating the file on each request - NOT trying to tell the browser to cache the file.

I am trying to enable output caching on all ashx files in my site. I'm trying to keep the server from generating the file on each request - NOT trying to tell the browser to cache the file.

I've distilled my ashx file down to this simple code:

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(),                                                DateTim开发者_高级运维e.Now.ToLongTimeString()));
        context.Response.Write(styleSheet.ToString());
    }
}

And in my web.config file, i have this:

<system.webserver>
    <caching enabled="true">
      <profiles>
        <add extension=".ashx" policy="CacheForTimePeriod" duration="00:01:00"  />
      </profiles>
    </caching>
</system.webserver>

Still, every request i make to the ashx file generates a new version with the current date and time in it.

What am i doing wrong?

Thanks.


Maybe this will help?

http://objectmix.com/dotnet/393333-output-caching-custom-http-handler.html

It would seem to suggest that since you're not using the normal page handler, the output caching module isn't invoked.

Simon


I was actually doing everything right, just not testing in the right environment. Once i deployed the simple example above on our IIS 7 server, it worked as expected with the code above. It should be noted that this DID NOT work on our IIS 6 server. I had not realized that this was a new feature only available in IIS 7

0

精彩评论

暂无评论...
验证码 换一张
取 消