DNN Forums

Ask questions about your website to get help learning DNN and help resolve issues.

Get User role for the current user

 5 Replies
 3 Subscribed to this topic
 40 Subscribed to this forum
Sort:
Author
Messages
Yma
Growing Member
Posts: 29
Growing Member

Hi,

I am using DNN 9.6

I have 5 custom user roles. I need to check if the currently logged-in user is in those custom user roles. And display the user role name. We consider one user has only one custom user role at a time. The user can be within one of user roles or not. We need to avoid the default DNN user roles. We have defined what are the custom user roles.

Ex:
custRole1
custRole2
custRole3
custRole4
custRole5

Please, can you help me to write this code in C# in a custom module or in a skin object? 

I really appreciate your support.

Thank you!

 

Veteran Member
Posts: 363
Veteran Member
4 Helpful Replier
Helpful Replier
Thanks for being such a helpful replier!
New Poster
New Poster
Congrats on posting!
4 Engaged Reader
Engaged Reader
You are an engaged reader!
2 Avid Reader
Avid Reader
Avid Reader art thou!
2 Most Liked
Most Liked
Congrats, your posts are really liked!

I recommend you jumping into GitHub (https://github.com/DNNCommunity) and creating a Pull Request (or maybe a new Issue) and you can mention that you're willing to support the programmer's time and perhaps you can get someone to help you out building this custom module.

Yma
Growing Member
Posts: 29
Growing Member
I can build the module if I can have the simple code for this request.
Senior Member
Posts: 1607
Senior Member
MVP
MVP
You're an MVP!
New Poster
New Poster
Congrats on posting!

If you have access to the UserInfo object for the user account, you can use the IsInRole() method. 

https://github.com/Upendo...curityService.cs#L32

Senior Member
Posts: 1322
Senior Member
3 Helpful Replier
Helpful Replier
Thanks for being such a helpful replier!
Lifesaver
Lifesaver
You're Life Saver!
New Poster
New Poster
Congrats on posting!
3 Engaged Reader
Engaged Reader
You are an engaged reader!

We have an example theme that could give you some starters for your code:

https://github.com/40fing...work-Attributes-Demo

Senior Member
Posts: 1322
Senior Member
3 Helpful Replier
Helpful Replier
Thanks for being such a helpful replier!
Lifesaver
Lifesaver
You're Life Saver!
New Poster
New Poster
Congrats on posting!
3 Engaged Reader
Engaged Reader
You are an engaged reader!

The Theme is (still) in VB, but I guess you'll get the point.
I added a Role filter example:

https://github.com/40fing...s-Security.ascx#L132

These Forums are for the discussion of the open source CMS DNN platform and ecosystem.

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

  1. If you have (suspected) security issues, please DO NOT post them in the forums but instead follow the official DNN security policy
  2. No Advertising. This includes the promotion of commercial and non-commercial products or services which are not directly related to DNN.
  3. 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.
  4. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  5. No Flaming or Trolling.
  6. No Profanity, Racism, or Prejudice.
  7. Site Moderators have the final word on approving / removing a thread or post or comment.
  8. English language posting only, please.

Would you like to help us?

Awesome! Simply post in the forums using the link below and we'll get you started.

Get Involved