Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Changing user roles programaticallyChanging user roles programatically
Previous
 
Next
New Post
3/13/2007 6:52 PM
 

After a lot of digging around ive found some odd stuff.

The most concernin of which is the fact that the usercontroller / userinfo NEVER hydrates userinfo.roles().

So that for example if you do:

Dim mynewInfo as userinfo = usercontroller.getuser(portalid,someuserid)

then mynewInfo.roles will ALWAYS be empty.

In fact the only time that the roles property is ever HYDRATED is as a side effect of the DotNetNuke.HttpModules.DNNMembershipModule provider.

OnAuthenticateRequest callback in the

Now while I understand why roles is being hydrated in the callback currently - as apart of the creation of the cookies and userinfo context setup -

Response.Cookies(

and

Context.Items.Add(

"UserInfo", myUserInfo)

 It does still mean that the userinfo.roles property is not really a fully valid member of the userinfo class.

It seems to me that the hydration of the roles property should be moved to the userinfo class in keeping with the element hydratable elements  Membership() and Profile()

Westa

"portalroles").Value = strRoles
 
New Post
3/13/2007 7:22 PM
 

OK - this is getting silly me thinks - it should not be so hard to change a user role on the fly.

THIS IS WHAT IVE GOT SO FAR IN TRYING TO FLUSH / RESET THE CACHE

Really would appreciate some feedback from the Core team here on this one

>>>>>>>>>>>>

Dim arrPortalRoles() As String
Dim objRoleController As New Security.Roles.RoleController
Dim CurrentDateTime As Date = DateTime.Now'Remove roles from the datacache
'DotNetNuke.Common.Utilities.DataCache.RemoveCache("GetRoles")

 

 

'Remove user from datacache
Dim UserInfoCacheKey As String = UserController.CacheKey(myUserInfo.PortalID, myUserInfo.Username)
DotNetNuke.Common.Utilities.DataCache.RemoveCache(UserInfoCacheKey)
'' create a cookie authentication ticket ( version, user name, issue time, expires every hour, don't persist cookie, roles )

 

 

 

 

 

 

 

 

'Dim PortalTicket As New FormsAuthenticationTicket(1, myUserInfo.Username, CurrentDateTime, CurrentDateTime.AddHours(1), False, PortalSettings.PortalAlias.PortalAliasID.ToString)
'' encrypt the ticket
'Dim strPortalAliasID As String = FormsAuthentication.Encrypt(PortalTicket)
'' send portal cookie to client
'Response.Cookies("portalaliasid").Value = strPortalAliasID
'Response.Cookies("portalaliasid").Path = "/"
'Response.Cookies("portalaliasid").Expires = CurrentDateTime.AddMinutes(1)' get roles from UserRoles table
arrPortalRoles = objRoleController.GetRolesByUser(myUserInfo.UserID, PortalId)' create a string to persist the roles
Dim strPortalRoles As String = Join(arrPortalRoles, New Char() {";"c})' create a cookie authentication ticket ( version, user name, issue time, expires every hour, don't persist cookie, roles )
Dim RolesTicket As New FormsAuthenticationTicket(1, myUserInfo.Username, CurrentDateTime, CurrentDateTime.AddHours(1), False, strPortalRoles)' encrypt the ticket
Dim strRoles As String = FormsAuthentication.Encrypt(RolesTicket)' send roles cookie to client
Response.Cookies("portalroles").Value = strRoles
Response.Cookies(
"portalroles").Path = "/"
Response.Cookies("portalroles").Expires = CurrentDateTime.AddMinutes(1)'Dim RoleTicket As FormsAuthenticationTicket = FormsAuthentication.Decrypt(Context.Request.Cookies("portalroles").Value)
myUserInfo.Roles = arrPortalRoles'myUserInfo.Roles = RoleTicket.UserData.Split(";"c)
Try
    Context.Items.Remove("UserInfo")
Catch ex As Exception
End Try

Context.Items.Add(

"UserInfo", myUserInfo)

 

 
New Post
3/14/2007 8:31 AM
 

So it seems that the only way to get a members roles to update is to log them off and then get them to log back in.

But surely this is crazy - does anyone have any suggestions here.

All I really want to be able to do is programatically change a user's roles - and have those changes actually happen to the current users session - so that new menu options appear - and the member gains access to new pages.

Westa

 
New Post
6/3/2007 11:25 AM
 

I am running into the same problem right now. I too have a page that can only be accessed by a certain role which I successfully place the user into. However the user can't access that page until logging off/on. I am right now testing against DNN 4.3.4.

So Westa, did anyone ever get back to you or did you find anything else out on your own?

Thanks,

Allan

 
New Post
6/4/2007 12:35 PM
 

The role information is stored in cookies and needs to be reloaded.

Here is a snippet of some code that may work for you. It adds a userlogin to the clearing of cookies,

Entities.Users.UserController.UserLogin

If you make any enhancements. let me know!

- Jim 

Had trouble posting code here, please check out this DNN Post and this post

 

 


Jim www.walkspoiled.com
 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Changing user roles programaticallyChanging user roles programatically


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out