刷新ASP.NET角色提供程序 [英] Refresh ASP.NET Role Provider

查看:135
本文介绍了刷新ASP.NET角色提供程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个简单的问题...

simple question...

鉴于我有一个ASP.NET站点,该站点使用[自定义] RoleProvider,
有什么方法可以以某种方式刷新"提供程序而不强迫用户注销站点并重新登录?

Given I have an ASP.NET site, which uses a [custom] RoleProvider,
Is there any way in which I can somehow "refresh" the provider without forcing the user to log out of the site and log back in?

我正在寻找类似于虚构方法的东西

I'm looking for something that would be akin to a fictional method

Roles.Refresh()

具体来说,我正在研究此问题,因为如果管理员更改了用户角色,则用户会话可能每隔10分钟刷新一次.

Specifically, I am looking at this for if an administrator changes a user's roles, the user sessions could maybe refresh themselves every 10 minutes or something.

推荐答案

我假设您在 web.config 中有类似的内容:

I assume you have something like this in your web.config:

<roleManager enabled="true" defaultProvider="..." 
             cacheRolesInCookie="true">

这些角色缓存在cookie中,因此您可以通过删除Cookie来强制刷新它们.这种方法对我有用.我添加了 cookieName 属性,以便不依赖于asp.net的默认设置.不过,对于您的情况,您可以只将 cookieTimeout 属性设置为合理的值并使用它来完成.

The roles are cached in a cookie , so you can force them to refresh by deleting the cookie. This method worked for me. I added the cookieName attribute so that I don't rely on asp.net's default. For your scenario, though, you may be able to just set the cookieTimeout attribute to something reasonable and be done with it.

当然,此方法不会立即更新角色.删除Cookie后,它们会在下一页加载时更新.

This method won't update the roles immediately, of course. They will be updated on the next page load after you delete the cookie.

这篇关于刷新ASP.NET角色提供程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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