ASP .NET 自定义 RoleProvider 不尊重 cacheRolesInCookie=“true" [英] ASP .NET Custom RoleProvider not respecting cacheRolesInCookie="true"

查看:29
本文介绍了ASP .NET 自定义 RoleProvider 不尊重 cacheRolesInCookie=“true"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了一个自定义角色提供程序,并在我的 web.config 文件中像这样配置它:

I've implemented a custom role provider, and configured it in my web.config file like this:

<roleManager enabled="true" defaultProvider="TDRoleProvider" cacheRolesInCookie="true">
  <providers>
    <clear/>
    <add name="TDRoleProvider" type="TDRoleProvider"/>
  </providers>
</roleManager>

我已经在我的自定义角色提供程序中覆盖了 GetRolesForUser 函数,并且我已经开始使用它,它工作得很好 - 为我正在测试的用户加载了 60 个角色.但是,我注意到每个调用 User.IsInRole 的请求都会调用 GetRolesForUser.在我编写的其他应用程序中,它只调用一次,然后将结果缓存在 cookie 中.出于某种原因,缓存不适用于此应用程序.关于原因的任何想法?

I've overridden the GetRolesForUser function in my custom role provider, and I've stepped into it, and it works just fine - loads up 60 roles for the user I'm testing with. However, I've noticed that the GetRolesForUser gets called on every request that calls User.IsInRole. In other apps I've written, it only calls it once, then caches the result in the cookie. For some reason, the caching is not working for this app. Any ideas as to why?

推荐答案

https://web.archive.org/web/20101123220352/http://connect.microsoft.com/VisualStudio/feedback/details/104688/rolemanager-cacherolesincookie-option-does-not-work

RolePrincipal 何时缓存(或不缓存)的问题经历了多次设计迭代,我们最终决定只缓存 IPrincipal 接口(即 IsInRole)暴露的方法."

"The issue of when to cache (or not cache) in RolePrincipal went through a number of design iterations, and we finally settled on only caching for the method exposed by the IPrincipal interface (i.e. IsInRole). "

这篇关于ASP .NET 自定义 RoleProvider 不尊重 cacheRolesInCookie=“true"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆