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.0Missing Role?Missing Role?
Previous
 
Next
New Post
11/2/2008 10:19 PM
 

Hi

I have an intermittent problem that I have not been able to resolve.  I create users dynamically and assign roles to them as appropriate. This is achieved via a call from a remote service.  Once created, users are redirected to the site and logged in automatically.  As part of the log in process, I determine which specific role a user is in, and direct them to a tab appropriate to that role.  Mostly this works fine, there are only a handful of roles of interest, and all have tested correctly.

However, every now and then, I get through the initial user creation process, and I can see that the user profile has been correctly created with the appropriate role assignment (via the admin user management control) however, I the role of interest to me does not appear in the objUser.IsInRole("") call.

My (truncated) code looks like the following

objUser.Roles = rc.GetRolesByUser(objUser.UserID, PortalId)
If (Not (objUser.Roles Is Nothing)) Then
    If objUser.IsInRole("xx") Then
tabName = "xx"
   ElseIf objUser.IsInRole("yy") Then
 tabName = "yy"

  'etc ...
    End If

Dim homeTab As DotNetNuke.Entities.Tabs.TabInfo = x.GetTabByName(tabName, PortalId)
If Not (homeTab Is Nothing) Then
Return "default.aspx?TabId=" + homeTab.TabID.ToString()
Else
_logger.Log(LogLevel.Debug, "Couldnt find tab name {0} !!", tabName)
Return String.Empty
End If 

I know all the roles exist in the system, and I can see wherever this fails that my user has been created correctly and been assigned to a role, so why does this code mostly work correctly, but occasionally fail?

Any assistance greatfully received..

Stuart

 

 

 
New Post
11/4/2008 1:20 PM
 

objUser.Roles = rc.GetRolesByUser(objUser.UserID, PortalId)

Not knowing what is above this code, I am guessing that you are attempting to set the user.Roles property with a GetRolesByUser. Interestingly the User.Roles property does the exact same thing during hydration, so unless you are doing something else with objUser or rc, you can probably just use...

If objUser.IsInRole("xx") then 'this will automatically hydrate Roles from the database if needed

What is not clear is if the users cookie is setup before or after your code. Otherwise when it fails you need to know what userid is being used at the time.


Dwayne J. Baldwin
 
New Post
11/4/2008 7:25 PM
 

Hi Dwayne

Thanks for the reply.  By the time this code is executed, the user is already logged in, so I already know the user, userid etc. THe GetRolesByUser method was added to see if it solved the missing role problem, however the issue remains.  As mentioned, it is an intermittent (but none the less important) issue that I need to resolve.  I can see from the admin user control that the user has been cretaed and is a member of one of the roles that I am looking for, and yet, that role does not appear in the full list of Roles (by iterating through the objUser.Roles array) and therefore never finds an appropriate match in objUser.IsInRole("xx") - Other roles do appear for the user, so it's not as if I'm not getting anything back at all.  Very strange..

Regards
Stuart

 
New Post
11/4/2008 8:48 PM
 

I suspect you're seeing a timing issue caused by the fact that portalroles are cached in a cookie so you need to expire them, something like the following should get you there:

DotNetNuke.Security.PortalSecurity.ClearRoles()
DataCache.ClearUserCache(PortalId, Username)


Buy the new Professional DNN7: Open Source .NET CMS Platform book Amazon US
 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Missing Role?Missing Role?


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