Developer forum

Forum » Development » How do i reload permission cache after i've imported users

How do i reload permission cache after i've imported users

Martin Nielsen
Reply

Hi DW,

 

I'm adding a bounch of users to a new group, but after adding the group the users, they cannot log in the the page when i've set up permission.

 

My Scenario:

 

2 extranet groups

- Extranet

 - Morten

 - Peter

 - Søren

- Special users

 

After my code runs i have this:

- Extranet

 - Morten

 - Peter

 - Søren

- Special users

 - Morten

 - Peter

 

Now when i go to a page where only Special users have access, they cannot login.....

 

I tried different methods to get it to work, but none of them allow my users to log in.

 

What do i need to call to allow my users to login?

 

 

BR

  Martin

 


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Martin,

 

If you are indeed sure that the users are part of the "Special users" Group, then you probably need to clear the Group cache. This is done this way:

 

 

// Clear UserManagement Group cache
Dynamicweb.Modules.UserManagement.Group.ClearCache();

 

Hope this helps :)

 

- Jeppe

 
Martin Nielsen
Reply

Hi Jeppe,

 

I don't think that method is public...  Any other ideas?

 

// Martin

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Which version of Dynamicweb are you using? This method has existed as a public static method since 8.2.0.1.

 

- Jeppe

 
Martin Nielsen
Reply

Ahh. building with an older DW solution.

 

It's there and public :-)

 

 

 
Martin Nielsen
Reply

Hi Jeppe,

 

I've tested this solution now, and it's not working for me.

I still cannot log in after i call

 

// Clear UserManagement Group cache
Dynamicweb.Modules.UserManagement.Group.ClearCache();

So far i do this in my code.

For each user i import, i save it via the API using:

 

// Save DW user (To clear DW cache)
Dynamicweb.Modules.UserManagement.User u = Dynamicweb.Modules.UserManagement.User.GetUserByID( Contact.AccessUserID );
u.Save();

When i'm done i call

 

// Make sure user can login
Dynamicweb.Modules.UserManagement.Group.ClearCache();

And then this:

 

      string appPath = string.Format( "{0}://{1}{2}{3}",
                               HttpContext.Current.Request.Url.Scheme,
                               HttpContext.Current.Request.Url.Host,
                               HttpContext.Current.Request.Url.Port == 80
                                   ? string.Empty
                                   : ":" + HttpContext.Current.Request.Url.Port,
                               HttpContext.Current.Request.ApplicationPath );

      string clearCacheUrl = appPath + "Default.aspx?Refresh=yes";


      WebClient wc = new WebClient();
      Stream webstream = wc.OpenRead( clearCacheUrl );

 

 

If i go into the user via backend and save the user there, i can log in after.

 

What am i missing.

 

// Martin

 

 

 

 

 
Morten Bengtson
Reply

Try this after the import is done... 

  1. Call Dynamicweb.Modules.UserManagement.Group.ClearCache() to clear the cached user groups.
  2. Call Dynamicweb.Content.Page.UpdateFrontendCache() to clear the cached permissions on websites and pages.

You don't have to call User.Save() for each user just to clear the cache. This will only make the import slow.

 

 

I hope this helps.

 

 

/Morten

 

 

 

 

 

 
Martin Nielsen
Reply

Hi Morten,

 

I think i found my error.

 

Your suggestions were neccesary, but i built my group string wrong aswell, so everything is OK now :-)

 

Thanks

 

// Martin

 

You must be logged in to post in the forum