在我的 web.config 中,我的角色管理器配置如下:
<roleManager enabled="true" cacheRolesInCookie="true" cookieName=".ASPROLES"
cookieTimeout="30" cookiePath="/" cookieRequireSSL="false"
cookieSlidingExpiration="true" cookieProtection="All">
然而,在我们的自定义 RoleProvider 中,似乎总是调用 GetRolesForUser 方法,而不是像我预期的那样,RoleManager 从其 cookie 中提供角色。
我们正在使用类似的方法来获取用户的角色:
string[] myroles = Role.GetRolesForUser("myuser");
我在配置或 RoleManager 的使用中是否缺少某些内容
最佳答案
您的 web.config 中缺少 defaultProvider="yourRoleProviderName"
。
您是为任何用户调用以下方法还是仅为当前用户调用以下方法? Cookie 缓存仅适用于当前用户角色。
Role.GetRolesForUser("myuser");
检查第一次调用 IsInRole
或 GetRoles
方法后,.ASPROLES cookie 是否发送到浏览器。
关于asp.net-mvc - 如果这样配置的话,asp.net RoleManager 真的会在 cookie 中缓存用户的角色吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/836043/