small problem with caching

Jun 9, 2009 at 12:07 AM

First of all thank you very much for coding all of this, i'm new to the scene but I was shocked to find out that MS only provide a SQL role provder out of the box, I only have a small # of users and groups so would like to not use database access - hence I found your work which was a great help.

I have a small problem with caching which I hope you can help me with.

First my setup:

I am developing locally with ASP.NET development server and in my web.config i am using NLTM authentication and just using your ROLEMANAGER implementation:

<authentication mode="Windows"/>

<roleManager enabled="true" defaultProvider="XmlRoleProvider">
      <providers>
          <clear/>
          <add applicationName="YOUR_APP" fileName="Roles.xml" name="XmlRoleProvider" type="Artem.Web.Security.XmlRoleProvider"/>
      </providers>
    </roleManager>

my XMl file is:

<ArrayOfXmlRole xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<XmlRole>
    <Name>Administrators</Name>
    <Users>
      <string>DOMAIN\userA</string>
      <string>DOMAIN\userB</string>
    </Users>
  </XmlRole>
</ArrayOfXmlRole>

When logged in as DOMAIN\userA it works fine, I can successfully check if the current logged in user is in a role by doing:

Roles.IsUserInRole("Administrators") (returns true)

However, while the application is running, if I change the XML file so that it reads:

<XmlRole>
    <Name>Administrators</Name>
    <Users>
      <string>DOMAIN\userC</string>
      <string>
DOMAIN\userB</string>
    </Users>
  </XmlRole>

Roles.IsUserInRole("Administrators") still returns true - it seems like the XML file is read and then is not read again unless the applcaition restarts. - as in the case of manual changes.

i am just worred that when in a live environment it will not be possible to manage the XML file manually without restarting the web application :(

i have tried to turn off caching, but this did not seem to work:

<roleManager enabled="true" defaultProvider="XmlRoleProvider" cacheRolesInCookie="false" maxCachedResults="0">

do you have any ideas how I can turn off caching or refresh the roles?

Coordinator
Jun 9, 2009 at 7:04 AM

Hi,

I think you are right and that have to be fixed.
In an earlier version of the providers I had cached set of roles and CacheDependency on the Roles.xml file.
Then because of some weird issues with cleared data from the file, because of that CacheDependency and CacheItemRemovedCallback used,  I have removed those dependency.

So, obviously, that's a partial solution.
In cases like yours the roles data will remain cached even when xml file is changed.

Now if you ask me why I did it like that, I will probably not find a reasonable answer :).
Maybe I was pressured by a lack of time and done just as a temporally solution which remains longer.

However, I’m still struggling a lack of time, but I will find some time to implement a proper solution by the end of this week.

Hope this helps.

Regards

Coordinator
Jun 15, 2009 at 8:58 PM

Hi,

I have just issued release 2.4, where that was fixed. 
Providers are notified for the files changes now and cached data is invalidated.

Regards

Jun 15, 2009 at 9:45 PM
Edited Jun 17, 2009 at 11:11 PM

oh thank you so much, i will test this week and let you know

EDIT: amazing - worked perfectly!