Small width layout Medium width layout Maximum width layout Small text Medium text Large text
     Search
Downloads Downloads Directory Directory Forums Forums Forge Forge Blogs Blogs        Marketplace Marketplace Careers Program Careers
Community › Forums Register  |  

  Need Help?  
Professional technical support for DotNetNuke is available from DotNetNuke Corporation.
 


  Ads  
 


  Sponsors  

Meet Our Sponsors

MaximumASP
SourceGear - Tools for Developers
.: CounterSoft :.
telerik
ExactTarget email software solutions
Merak Mail Server
 


DotNetNuke Forums
 
  Forum  General DotNetN...  Extend It! ( Pr...  Adding a role to a user programatically.
Previous Previous
 
Next Next
New Post 12/6/2007 6:34 AM
User is offline Gregg Froelich
17 posts
10th Ranked


Adding a role to a user programatically. 

Our application requires users to be able to access certain pages only after they've completed other pages on our site.  So i add roles to the users account after they've finished certain things.  The code I use is below.  The problem that recently started was that the role gets added immediately, but the user can't access a page until 30 seconds to a minute after the role was added. 

It worked before, but over the past few days i've noticed that this isn't happening immediatley any more.  Are there any host settings that need to be set for this to work?  Any suggestions would be great.  We are using version 04.04.01.  And I'm using vs 2003 to program it. 

Thanks,


Gregg

 

This code fires on a cmdUpdate click event.

 Dim objCtlRole As New DotNetNuke.Security.Roles.RoleController Dim objRoleInfo As New DotNetNuke.Security.Roles.RoleInfoTrue) Dim arrPortalRoles() As String = objCtlRole.GetRolesByUser(UserId, PortalId) Dim strPortalRoles As String = String.Join(";", arrPortalRoles) Dim RolesTicket As New System.Web.Security.formsAuthenticationTicket(1, UserInfo.Username, DateTime.Now.AddHours(-1), DateTime.Now.AddHours(-1), False, strPortalRoles) Dim strRoles As String = System.Web.Security.formsAuthentication.Encrypt(RolesTicket)'  send roles cookie to client

 Response.Cookies("portalroles").Value = strRoles

 Response.Cookies("portalroles").Path = "/"

 Response.Cookies("portalroles").Expires = DateTime.Now.AddHours(-1)

 

End If

 

 

 

 DataCache.ClearPortalCache(PortalId,

 

 

 

 

 

 
New Post 1/15/2008 3:07 PM
User is offline Dylan Barber
634 posts
codegalaxy.com
7th Ranked


Re: Adding a role to a user programatically. 

I do it this way - not sure why you might be having time problems mine alsways seem to be instant

 

     Dim objRoleController As DotNetNuke.Security.Roles.RoleController
                objRoleController = New DotNetNuke.Security.Roles.RoleController
                objRoleController.AddUserRole(PortalId, User.UserID, Convert.ToInt32(Me.rblRoles.SelectedItem.Value), Null.NullDate, Null.NullDate)

 

user.userid is obviously the user id and me.rblrolesetcetc is the role you want to add them to - (the id not the string name)

 
New Post 1/28/2008 9:47 AM
User is offline Gregg Froelich
17 posts
10th Ranked


Re: Adding a role to a user programatically. 

Thanks,

My issue is that, the role is created for the user, but sometimes it takes up to 5 minutes to see it show up for the user.  It is immediately entered into the db, but a page will tell the user that they do not have access.  But if they wait a few minutes they can access the page.

It happens occassionally with different users in different locations.  So I'm not sure if there is  a browser setting that needs to be set on the clients browser.

Any info would be great.

Gregg

 
New Post 1/28/2008 11:09 AM
User is offline cathal connolly
2375 posts
www.cathal.co.uk
5th Ranked










Re: Adding a role to a user programatically. 

Gregg,

the code you're using is correct. However by the time it's executed the page_load has already ran which means the security context is loaded for that page. You need to force another page load (usually via a response.redirect) to allow dotnetnuke to detect the cookie with the portalroles is expired, rerun the security code and create a new cookie with the new role(s).

Cathal

 
New Post 1/28/2008 1:05 PM
User is offline Gregg Froelich
17 posts
10th Ranked


Re: Adding a role to a user programatically. 

Thanks Cathal,

Are you saying i need to create the cookie after the redirect? 

The next line after the code posted is response.redirect(navigateurl(tabid)).  Do I have to run the security code and create a new cookie after the redirect? 

 

 
Previous Previous
 
Next Next
  Forum  General DotNetN...  Extend It! ( Pr...  Adding a role to a user programatically.
 


Forum Policy

These Discussion Forums are dedicated to the discussion of the DotNetNuke Web Application Framework.

For the benefit of the community and to protect the integrity of the project, 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 DotNetNuke.
2. Discussion or promotion of DotNetNuke product releases under a different brand name are strictly prohibited.
3. No Flaming or Trolling.
4. No Profanity, Racism, or Prejudice.
5. Site Moderators have the final word on approving/removing a thread or post or comment.
6. English language posting only, please.

 


DNNCovered.com - Your Offshore Dotnetnuke Partner
Dnncovered.com is the only Dotnetnuke offshore outsourcing center specializes in DNN skinning and module development with lowest pricing and quality service. Our staff is dedicated to websites based on DNN and our graphic designers are creative and imaginative well enough to provide customers the complete set of skinning solutions and packages
www.dnncovered.com
PointClick.Net DNN Solutions
DotNetNuke Hosting Platform for Business and personal use.
PointClick.Net Hosted Solutions
Advanced Web Portals by Infoscaler
Infoscaler is a California based company that provides advanced Web Portals, E-commerce Sites, Database Applications and Intranet Solutions on the DotNetNuke and Microsoft.NET platforms.
www.infoscaler.com

DotNetNuke Corporation   Terms Of Use  Privacy Statement
DotNetNuke®, DNN®, and the DotNetNuke logo are trademarks of DotNetNuke Corporation
Hosted by MaximumASP