【问题标题】:WCF OperationContract is 304 in IE (7-9) but not Firefox or ChromeWCF OperationContract 在 IE (7-9) 中为 304,但不是 Firefox 或 Chrome
【发布时间】:2012-05-21 16:51:40
【问题描述】:

我有一个运行 .net 4.0 的 IIS 6 服务器,它为 IE 返回 304(未修改),但不是 Firefox 或 Chrome。我从不希望保存 .svc 文件中的这个和其他调用缓存,但始终是 200 和新数据。我没有在运行 IIS7.5 的 Win7 上的 localhost 上看到这个。 响应头有一个 Cache-Content: private 并且在 IIS 6 下运行时,Fiddler 甚至不显示请求。

[OperationContract]
[WebGet(UriTemplate = "usertoken/populate")]
public ClientUserToken PopulateUserToken()
{
  return HttpContext.Current.Session["userToken"] as UserToken;
}

我可以为每个方法添加一个 [AspNetCacheProfile("NoCachingProfile")] 并且

<outputCacheSettings>
    <outputCacheProfiles>
        <add name="NoCachingProfile" noStore="true" duration="0" varyByParam="none" enabled="false"/>
    </outputCacheProfiles>
</outputCacheSettings>

到 web.config,但我想避免将其添加到每个操作中。 是否有 IIS 设置来执行此操作,还是应该由代码驱动?为什么只发生在 IE 中?

【问题讨论】:

    标签: wcf internet-explorer iis iis-6 browser-cache


    【解决方案1】:

    这不是服务的问题,是 IE 的问题。 Fiddler 没有显示任何内容,因为浏览器没有发送任何内容,它正在使用最后缓存的响应。如果可以,请使用 Post,否则使每个 Get 请求看起来不同,例如: url: "usertoken/populate?" + new Date().getTime() 旧的 IE 使用 Gets 忽略无缓存很糟糕

    【讨论】:

    • 我的设置放入的 Cache-Control private, no-store, max-age=0 似乎在 IE7+ 中有效,所以它也不能忽略那个。当您将缓存设置为 false 时,我在 api.jquery.com/jQuery.ajax 中看到了您的方法,这看起来是一个不错的方法。谢谢!
    猜你喜欢
    • 2015-07-11
    • 2017-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多