客户端缓存从 HTTPHandler 返回的 XML

发布于 2024-10-03 21:07:51 字数 582 浏览 0 评论 0原文

我有一个返回一些 XML 的 HTTPHandler。我试图弄清楚如何将其缓存在浏览器中,就好像它是一个静态 XML 文件一样。

我已经尝试过这个以及其他一些变体和其他缓存选项,但我所做的一切似乎都无法使其缓存(根据 Fiddler)。

关于如何在客户端浏览器上缓存输出有什么想法吗?

public void ProcessRequest(HttpContext context)
{
        context.Response.ContentType = "text/xml";
        context.Response.ContentEncoding = System.Text.Encoding.UTF8;

        context.Response.Cache.SetCacheability(HttpCacheability.Private);
        context.Response.Cache.SetMaxAge(new TimeSpan(1, 0, 0));

        string sXml = GetTableAsXml();
        context.Response.Write(sXml);
}

I have an HTTPHandler that returns some XML. I am trying to figure out how to get this to cache in the browser, as if it were a static XML file.

I've tried this along with a few other variations and other Cache options, but nothing I do seems to make it cache (according to Fiddler).

Any ideas on how I can cache the output on the client's browser?

public void ProcessRequest(HttpContext context)
{
        context.Response.ContentType = "text/xml";
        context.Response.ContentEncoding = System.Text.Encoding.UTF8;

        context.Response.Cache.SetCacheability(HttpCacheability.Private);
        context.Response.Cache.SetMaxAge(new TimeSpan(1, 0, 0));

        string sXml = GetTableAsXml();
        context.Response.Write(sXml);
}

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

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

发布评论

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

评论(1

多彩岁月 2024-10-10 21:07:51

此帖子可能会对您有所帮助。

This thread might help you.

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