如何撤消Response.Cache.SetNoStore()?
我有一个CMS应用程序代码,它在所有请求上调用Response.Cache.SetNoStore()
,如果我是正确的,这将阻止代理/ cdn缓存这些页面/内容。 因此,我有条件地调用以下代码:
Response.Cache.SetCacheability(HttpCacheability.Public); Response.Cache.SetMaxAge(new TimeSpan(0, 30, 0)); Response.Cache.SetValidUntilExpires(true);
但这并没有从响应头中取出no-store参数,这是返回的http头:
Cache-Control:public, no-store, must-revalidate, max-age=1800
因此,我的问题是,如何才能真实地取出nostore param? 如果这是不可能的,我如何/在哪里解析/修改http-header,因为我试图在PagePreRender事件上解析并且nostore param尚未应用…这导致想知道哪个生命周期是这个附加到标题?
有一种方法可以在调用后撤消SetNoStore
。 您需要使用一些创意路由以不同的方式处理请求或reflection以调用私有的内置重置。
您可以访问HttpCachePolicyWrapper
以访问底层HttpCachePolicy
,然后分配内部NoStore
字段或发出Reset
以恢复为默认缓存策略。
response.Cache.SetNoStore(); // assign no-store BindingFlags hiddenItems = BindingFlags.NonPublic | BindingFlags.Instance; var httpCachePolicyWrapper = response.Cache.GetType(); // HttpCachePolicyWrapper type var httpCache = httpCachePolicyWrapper.InvokeMember("_httpCachePolicy", BindingFlags.GetField | hiddenItems, null, response.Cache, null); var httpCachePolicy = httpCache.GetType(); // HttpCachePolicy type // Reset Cache Policy to Default httpCachePolicy.InvokeMember("Reset", BindingFlags.InvokeMethod | hiddenItems, null, httpCache, null); var resetAllCachePolicy = httpCachePolicy.InvokeMember("_noStore", BindingFlags.GetField | hiddenItems, null, httpCache, null); response.Cache.SetNoStore(); // assign no-store // Undo SetNoStore Cache Policy httpCachePolicy.InvokeMember("_noStore", BindingFlags.SetField | hiddenItems, null, httpCache, new object[] { false }); var resetNoStoreOnly = httpCachePolicy.InvokeMember("_noStore", BindingFlags.GetField | hiddenItems, null, httpCache, null);
- .net图表清除并重新添加
- 如何从asp.net中的代码调用确认消息?
- ASP.NET中的System.Web.HttpContext.Current.User.Identity.Name与System.Environment.UserName的对比
- 在Visual Studio 2015中安装entity framework失败
- 如何防止用户从多个位置或同一台PC上的不同浏览器登录
- 强制asp.net下拉列表进行扩展
- 正确使用jQuery.Ajax脚本中JSON的返回值
- 异步调用webservice并等待所有线程完成
- Castle Windsor ASP.NET MVC 4和Web API相同的应用程序。 只有MVC控制器没有依赖关系?