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.0Checking for admin status in code?Checking for admin status in code?
Previous
 
Next
New Post
10/6/2006 5:03 AM
 
Hey forummers,

I wanted to ask how to properly check for admin status when coding a module? Using "UserInfo.IsSuperUser" returns "True" only if the host is logged in, and I'd really like to be able to see if an admin is looking at the module. I apologise if this has been covered before but have had little luck in finding related issues.

Thanks a ton in advance...

Regards,

Gazoo
 
New Post
10/6/2006 11:17 AM
 

This really depends on what you mean by "admin status".  IsSuperUser will tell you if the user has Host privs.  This is of course admin +.  You have the Administrators role, which are admins and you also have people with Edit privs on your page/module.  That could also be considered admin.

If you want to know if someone is a SuperUser, then what you have above, UserInfo.IsSuperUser, will return true/false and you will know if that user has Host privs.

If you want to see if someone is in the Administrators role, you could use UserInfo.IsInRole("Administrators").  This too will return a true/false value.  Note, you can check for any role by simply entering the rolename.

If you want to see if someone has Edit privs on your page/module, you can use IsEditable to return the true/false value of whether or not the user can edit your module.

Lastly, if you want to see if your user is view Anonymously, you can simply check for that userid (UserID = -1).

Now all of this presumes the user is logged in.  Unless you are allowing All Users or Unauthenticated Users the right to Edit, you will not know if the user has any of these rights.

To see how this works, drop a label (Label1) on your module and add this code to your Page_Load event.  You will see the various status when you look at it as Host, Administrator, User in role with Edit privs, Registered User (no edit privs), and Unauthenticated User.

   If UserInfo.IsSuperUser Then
     Label1.Text = "User has Host Privs (Super User)"
   ElseIf UserInfo.IsInRole("Administrators") Then
     Label1.Text = "User is an Administrator"
   ElseIf IsEditable Then
     Label1.Text = "User has Edit privs"
   ElseIf UserId = -1 Then
     Label1.Text = "User is viewing Anonymously"
   Else
     Label1.Text = "User has no privs"
   End If

 
New Post
10/11/2006 5:58 AM
 
Hey,

Thanks a bunch for the help - this was exactly what I was looking for. I've ended up using the "isEditable". I assume that's normal procedure...

Regards,

Gazoo
 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Checking for admin status in code?Checking for admin status in code?


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