简体   繁体   English

在WCF服务中设置HTTP缓存控制头

[英]Setting HTTP cache control headers in WCF service

I'm working on an HTTP REST service implemented on WCF. 我正在研究在WCF上实现的HTTP REST服务。 I'd like to set the HTTP cache control headers for my operations appropriately. 我想适当地为我的操作设置HTTP缓存控制头。

I've seen a few examples that involve using the WebOperationContext.Current.OutgoingResponse to modify the headers in each method. 我已经看到一些涉及使用WebOperationContext.Current.OutgoingResponse修改每个方法中的标头的示例。 But let's be honest, that's a pain in the butt, especially since nearly all of my operations are going to use the same cache control policy (no-cache). 但是说实话,这是一个痛苦的屁股,特别是因为几乎所有的操作都将使用相同的缓存控制策略(无缓存)。

I'm thinking there must be an elegant way to set this. 我认为必须有一种优雅的方式来设置它。 Perhaps a combination of a ServiceBehavior to set a service-level default, and OperationBehaviors to override that for certain operations? 也许ServiceBehavior的组合可以设置服务级别的默认值,而OperationBehaviors可以覆盖某些操作的默认值? Or maybe there's some better way to do this? 或者也许有更好的方法来做到这一点?

WCF services respect the outputCache setting in the Web.Config. WCF服务遵循Web.Config中的outputCache设置。 Additionally you can specify OutputCacheProfiles which are also defined in the Web.config and then specify which OutputCacheProfle to use at the method level with decorators . 此外,您可以指定也在Web.config中定义的OutputCacheProfile ,然后指定在方法级别使用装饰器的OutputCacheProfle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM