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.0Logged in UserLogged in User's Role Detail
Previous
 
Next
New Post
12/29/2008 5:42 AM
 

Hi Team,

I want to get the loggedin User's RoleID.

Using DNN we can add multiple roles againts one user. So when when user logs in system returns me string array of Roles(Name) and from that I am not able to find out the roleID. I require the RoleID as I have defined some activities against RoleID in databse. So can anyone let me know how to get exact rolename and roleID of logged in User.

 

 

 

 
New Post
12/29/2008 10:59 AM
 
  • GetPortalRoles: Returns all roles for a specified portal. Input to the stored procedure is PortalID, and output is all data from the Roles table for
    the specified portal.
     
  • GetRoleMembership: Inputs PortalID, optional RoleID, and optional UserID and returns all roles, and/or members of a specific role.
     
  • GetRolesByUser: Accepts a UserID and PortalID and returns all the roles the user is assigned for a particular portal.
     
  • AddUserRole: For adding a user to a specific role.

 

We check the DNN roles against the roles from our edit settings by looping through the array:
 

'make a call the users class.
Dim objUser As New UsersDB

'now execute the stored procedures to get all the portal roles.

Dim EditArticleRoles As SqlDataReader = objUser.GetPortalRoles(PortalId)

' Clear existing items in checkboxlist
chkAuthArticleRoles.Items.Clear()
Dim aryAuthArticlesRoles As String()
'now populate the array with the delimited string that was previously
'stored in the module settings hash table value of "AuthArticleRoles".

aryAuthArticlesRoles = Split(CType(Settings("AuthArticlesRoles"), String), ";")

Dim allEditArticleItems As New
System.Web.UI.WebControls.ListItem
allEditArticleItems.Text = "All Users"
allEditArticleItems.Value = glbRoleAllUsers
'check and see if all users are allowed to access the module, if so check the checkbox.
If InStr(1, Settings("AuthArticlesRoles"), glbRoleAllUsers & ";") <> 0 Then
allEditArticleItems.Selected = True
End If

chkAuthArticleRoles.Items.Add(allEditArticleItems)


Dim iArt As Integer
'now go through all the roles and check them against our array to see
'what roles should be selected for the module.

While EditArticleRoles.Read()
Dim itemArt As New System.
Web.UI.WebControls.ListItem
itemArt.Text = CType(EditArticleRoles("RoleName"), String)
itemArt.Value = EditArticleRoles("RoleID").ToString()
For iArt = 0 To UBound(aryAuthArticlesRoles)
If aryAuthArticlesRoles(iArt) = itemArt.Value Then
itemArt.Selected = True
End If
Next
chkAuthArticleRoles.Items.Add(itemArt)
End While


 

Now that we have the roles defined we want to check and see if a user is in one of the roles that we specified in the edit module. So in the user control do the following; we get all the roles that the user has associate with them and check them against the roles we selected in the edit module. For this application we have roles that can add articles to the module:

Dim objSec2 As New UsersDB 
Dim dr As String() = objSec2.GetRolesByUser(Context.User.Identity.Name, _
PortalId)
Dim i As Integer
For i = 0 To UBound(dr)
'check to see if the role is defined for edit access as
'we set previously in our edit module.

If InStr(Settings("AuthEditRoles"), CType(dr(i), String) & ";") And _
(CType(dr(i), String) <> "") Then
SiteEdit = True
End If
Next


 

The above method is one way to get all the roles for a specific user. The next method is making a call and checking to see if a user is in a particular role or roles:
 

Dim objSecurity As PortalSecurity 
'here we pass our delimited string value to the method and it will
'return a true or false if the user is in the role or not.

If objSecurity.IsInRoles(CType(Settings("AuthArticlesRoles"), String)) Then
rowArticle.Visible = True
End If


 

In this next example, we have a transaction that occurs, if the transaction is successful, then we add a user to a specific role. This example is pulled from a PayPal IPN transaction. Once PayPal says the transaction was successful, we'll add the user to role that was specified in the edit module for this particular application:


 

 

If Trim(strPurchaseRoles) <> "" Then
'add user to role(s)
Dim objUser As New UsersDB
Dim aryPurchaseRoles As String()
aryPurchaseRoles = Split(CType(Settings("PurchaseRoles"), String), ";")
Dim i As Integer
For i = 0 To UBound(aryPurchaseRoles)

'add the user to each role specified in the settings hash value of PurchaseRoles.
objUser.AddUserRole(PortalID, aryPurchaseRoles(i), intUserID)
Next
End If

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Logged in UserLogged in User's Role Detail


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