AZMan Rolemanager keeps roles cached and does not reflect changes for a long time

If you have found this article, you already know who Mr. Azman is and what I am talking about here. So, I will not go into the details to explain you what asp.net 2.0 Rolemanager is and what all options it gives us to store role and membership information.

Here is the excerpt from my web.config file :

<!–In this case my Roles are stored in an XML file, your roles can reside in SQL Server or AD or ADAM, it doesn’t matter–>

<add name=AzManPolicyStore connectionString=msxml://C:/Azman.xml />

<!–Here
is how we enable the role manager. In this case the built in ASP.Net
website config tool will automatically read and write Roles and their
membership info in the file mentioned above. i.e Azman.xml–>

<roleManager enabled=true defaultProvider=RoleManagerProvider>

<providers>

<add name=RoleManagerProvider

type=System.Web.Security.AuthorizationStoreRoleProvider,
System.Web, Version=2.0.0.0, Culture=neutral,
publicKeyToken=b03f5f7f11d50a3a

connectionStringName=AzManPolicyStore

applicationName=TestApp/>

</providers>

</roleManager>

 

You must have noticed that in this example my Role data store is c:azman.xml file. The problem that I was facing was that, whenever I would make changed to my role membership by using ASP.Net web configuration tool, it would update the .xml file perfectly fine, but ASP.net would still continue using the cached roles that it had loaded when I started my application.

After some research I found out that, the the default behavior of Rolemanager is to cache roles in memory for 60 minutes. This might be unacceptable for some people. So, the solution for this is to add cacheRefreshInterval=”x” to your RoleManagerProvider node. The X can be as low as 1 which would mean 1 minute, but you can change to whatever suits you best.

<add name=RoleManagerProvider

type=System.Web.Security.AuthorizationStoreRoleProvider,
System.Web, Version=2.0.0.0, Culture=neutral,
publicKeyToken=b03f5f7f11d50a3a

connectionStringName=AzManPolicyStore

cacheRefreshInterval=”1

applicationName=TestApp/>

One Response

  1. Thanks Nishant…that sneaky Mr Azman!

Leave a Reply