How to check if a user is logged in or not

How can I check sitecore that the current user is an administrator?

sort of:

if(User.Current.Name == "extranet\Admin") // then do some thing ?? 
+6
source share
5 answers

Sitecore.Security.Accounts.User class has a built-in IsAdministrator property:

  Sitecore.Context.User.IsAdministrator 
+15
source

In fact, you can just call Sitecore.Context.IsAdministrator

+3
source

This should do what you wanted:

 Sitecore.Context.User.IsInRole("extranet\admin") 
+2
source

Note \ is an escape in C # use "extranet\\Admin" and the CMS administrator is sitecore \ admin

I assume that you need to know your extranet administrator. this is a good idea for creating roles, there may be several administrators (not sure if the IsAdministrator property works well for an extranet)

 Sitecore.Context.User.IsInRole("extranet\\your extranet admin rol"); 

If you do not have an Extranet administration command and you do not want it, you can use what you already have if (Sitecore.Context.User.Name == "extranet\\Admin")

0
source

You can try this code:

 var result = Sitecore.Context.User.IsAdministrator; 

If the administrator is registered as a result, this is true, otherwise the result will be false.

0
source

All Articles