asp.net-mvc – 防止在ASP.NET MVC中缓存属性,每次执行一个Action时强制执行属性
发布时间:2020-05-23 01:57:09 所属栏目:asp.Net 来源:互联网
导读:根据各种文章(例如 here和 here),可以缓存ASP.NET MVC操作的属性结果,并且在调用控制器操作时不再执行. 在我的情况下,这种行为是不可取的(例如,我有一个基于我自己的属性和IP的授权系统,每次都需要执行的角色检查,以及其他事情). 如何阻止ASP.NET MVC缓存我的
|
根据各种文章(例如 here和 here),可以缓存ASP.NET MVC操作的属性结果,并且在调用控制器操作时不再执行. 在我的情况下,这种行为是不可取的(例如,我有一个基于我自己的属性和IP的授权系统,每次都需要执行的角色检查,以及其他事情). 如何阻止ASP.NET MVC缓存我的属性/属性执行结果并保证每次都执行它们? 解决方法查看AuthorizeAttribute的源代码(在Codeplex上或通过Reflector),了解如何关闭授权页面的缓存.我将它重构为我的自定义授权属性的单独方法,该属性派生自AuthorizeAttribute.protected void CacheValidateHandler( HttpContext context,object data,ref HttpValidationStatus validationStatus )
{
validationStatus = OnCacheAuthorization( new HttpContextWrapper( context ) );
}
protected void SetCachePolicy( AuthorizationContext filterContext )
{
// ** IMPORTANT **
// Since we're performing authorization at the action level,the authorization code runs
// after the output caching module. In the worst case this could allow an authorized user
// to cause the page to be cached,then an unauthorized user would later be served the
// cached page. We work around this by telling proxies not to cache the sensitive page,// then we hook our custom authorization code into the caching mechanism so that we have
// the final say on whether a page should be served from the cache.
HttpCachePolicyBase cachePolicy = filterContext.HttpContext.Response.Cache;
cachePolicy.SetProxyMaxAge( new TimeSpan( 0 ) );
cachePolicy.AddValidationCallback( CacheValidateHandler,null /* data */);
} (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc-2 – 带有数组/列表的ASP.NET MVC 2模型
- asp.net-mvc – ASP.NET MVC Beta支持列表中的Model Binder
- asp.net-mvc-3 – ASP.NET MVC 3: – 使用数据库而不是资源
- CORS支持PUT和DELETE与ASP.NET Web API
- asp.net-mvc – 为什么Nant不与TeamCity合作?
- ASP.NET C#ListBox服务器控件不会禁用
- asp.net-mvc – 创建一个texarea帮助器,它将视图的内容作为
- asp.net-mvc – 在ASP.Net MVC 2中为非归因模型验证提供本地
- asp.net-mvc – 使用嵌套显示模板时如何防止Razor向输入添加
- asp.net – 一个明智的PasswordStrengthRegularExpression
推荐文章
站长推荐
- asp.net – 表单身份验证web.config设置
- asp.net – 如何将JsonResult对象作为字符串获取
- 所有我使用IO的动作都是异步的?
- asp.net中的会话,缓存和配置文件有什么区别
- asp.net-mvc – 在实体框架代码中为同一表定义多
- asp.net – 使用jquery调用ascx页面方法
- asp.net-mvc-4 – MVC 4 Razor如果拆分div标签
- asp.net-mvc – ASP.NET MVC 4路由 – controlle
- asp.net – 如何在runat =“server”表单元素中包
- asp.net – compilation debug =“true”和发布模
热点阅读
