【问题标题】:How does AssemblyResourceLoader/ASP.Net handle If-Modified-Since header?AssemblyResourceLoader/ASP.Net 如何处理 If-Modified-Since 标头?
【发布时间】:2011-01-13 04:38:11
【问题描述】:

我有一个类似于 AssemblyResourceLoader 的 IHttpHandler。它所做的是生成图像,然后将其发送回浏览器。

在 AssemblyResourceLoader 中有这样的代码块:

    HttpCachePolicy cache = context.Response.Cache;
    cache.SetCacheability(HttpCacheability.Public);
    cache.VaryByParams["d"] = true;
    cache.SetOmitVaryStar(true);
    cache.SetExpires(DateTime.Now + TimeSpan.FromDays(365.0));
    cache.SetValidUntilExpires(true);
    Pair assemblyInfo = GetAssemblyInfo(assembly);
    cache.SetLastModified(new DateTime((long) assemblyInfo.Second));

我已将我的设置为发出与 AssemblyResourceLoader 完全相同的标头。我设置了 Last-Modified 标头,浏览器将 If-Modified-Since 标头发送到我的处理程序,就像使用 AssemblyResourceLoader 一样。问题是这样的:我的处理程序永远不会像 AssemblyResourceLoader 那样返回 304。我在 AssemblyResourceLoader 代码中找不到处理 If-Modified-Since 标头的任何地方,所以我不知道如何自己处理它。有谁知道 ASP.Net 在哪里做的以及我如何从我的处理程序中获得相同的行为?

谢谢。

【问题讨论】:

    标签: asp.net http-headers


    【解决方案1】:

    看起来你需要自己做,但并不难:http://www.motobit.com/tips/detpg_net-last-modified/

    【讨论】:

    • 我喜欢这样,但我不想自己做。 AssemblyResourceLoader 不做任何事情。我在想 asp.net 中有一些东西可以处理它,所以我希望能够利用它。
    • 嗯,stackoverflow 链接有帮助吗?
    • 没有那么多,因为它在谈论“Expires”标头,我正在寻找有关 ASP.Net 如何处理“If-Modified-Since”标头的信息。
    • 再想一想,即使 ASP.Net 可以处理那个标头,它怎么知道它什么时候被修改过而我不告诉它呢?正确的解决办法是自己处理。感谢您的链接。
    猜你喜欢
    • 2012-11-01
    • 2012-06-06
    • 2016-12-10
    • 2016-04-02
    • 2011-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-03
    相关资源
    最近更新 更多