Skip to main content
Code readability
Source Link
Richard Seal
  • 20.8k
  • 5
  • 44
  • 79

To get a user by a username you can use :

  public class UserRepository
  {
    public static User GetUser(string domainName, string userName)
    {
       if (User.Exists(domainName + @"\" + userName))
       {
           return User.FromName(domainName + @"\" + userName, true);
       }
       return null;
    }
  }

To get a user roles you can use

  Sitecore.Security.Accounts.User user = UserRepository.GetUser("yourdomain","youruserName");
       
  if (user==null) return;
      
  var rolesList = user.Roles.ToList();

  foreach(var role in rolesList)
  {
     var roleName = role.DisplayName;
     var roleDomain = role.Domain;
     // you have all the properties of a role in role object
  }

To get a user by a username you can use :

  public class UserRepository
  {
    public static User GetUser(string domainName, string userName)
    {
       if (User.Exists(domainName + @"\" + userName))
            return User.FromName(domainName + @"\" + userName, true);
          return null;
    }
  }

To get a user roles you can use

  Sitecore.Security.Accounts.User user = UserRepository.GetUser("yourdomain","youruserName");
       
  if (user==null) return;
      
  var rolesList = user.Roles.ToList();

  foreach(var role in rolesList)
  {
     var roleName = role.DisplayName;
     var roleDomain = role.Domain;
     // you have all the properties of a role in role object
  }

To get a user by a username you can use :

public class UserRepository
{
    public static User GetUser(string domainName, string userName)
    {
       if (User.Exists(domainName + @"\" + userName))
       {
           return User.FromName(domainName + @"\" + userName, true);
       }
       return null;
    }
}

To get a user roles you can use

  Sitecore.Security.Accounts.User user = UserRepository.GetUser("yourdomain","youruserName");
       
  if (user==null) return;
      
  var rolesList = user.Roles.ToList();

  foreach(var role in rolesList)
  {
     var roleName = role.DisplayName;
     var roleDomain = role.Domain;
     // you have all the properties of a role in role object
  }
deleted 90 characters in body
Source Link
Vlad Iobagiu
  • 18.8k
  • 2
  • 27
  • 53

To get a user by a username you can use :

  public class UserRepository
  {
       public static User GetUser(string domainName, string userName)
        {
          
          if (User.Exists(domainName + @"\" + userName))
            return User.FromName(domainName + @"\" + userName, true);
          return null;
        }
    }

To get a user roles you can use

       Sitecore.Security.Accounts.User user = UserRepository.GetUser("yourdomain","youruserName");
       
       if (user==null) return;
      
       var rolesList = user.Roles.ToList();

       foreach(var role in rolesList)
        {
            var roleName = role.DisplayName;
            var roleDomain = role.Domain;
            // you have all the properties of a role in role object
        }

To get a user by a username you can use :

 public class UserRepository
  {
       public static User GetUser(string domainName, string userName)
        {
          
          if (User.Exists(domainName + @"\" + userName))
            return User.FromName(domainName + @"\" + userName, true);
          return null;
        }
    }

To get a user roles you can use

       Sitecore.Security.Accounts.User user = UserRepository.GetUser("yourdomain","youruserName");
       
       if (user==null) return;
      
       var rolesList = user.Roles.ToList();

       foreach(var role in rolesList)
        {
            var roleName = role.DisplayName;
            var roleDomain = role.Domain;
            // you have all the properties of a role in role object
        }

To get a user by a username you can use :

  public class UserRepository
  {
    public static User GetUser(string domainName, string userName)
    {
       if (User.Exists(domainName + @"\" + userName))
            return User.FromName(domainName + @"\" + userName, true);
          return null;
    }
  }

To get a user roles you can use

  Sitecore.Security.Accounts.User user = UserRepository.GetUser("yourdomain","youruserName");
       
  if (user==null) return;
      
  var rolesList = user.Roles.ToList();

  foreach(var role in rolesList)
  {
     var roleName = role.DisplayName;
     var roleDomain = role.Domain;
     // you have all the properties of a role in role object
  }
added 51 characters in body
Source Link
Vlad Iobagiu
  • 18.8k
  • 2
  • 27
  • 53

To get a user by a username you can use :

 public class UserRepository
  {
       public static User GetUser(string domainName, string userName)
        {
          
          if (User.Exists(domainName + @"\" + userName))
            return User.FromName(domainName + @"\" + userName, true);
          return null;
        }
    }

To get a user roles you can use

       Sitecore.Security.Accounts.User user = UserRepository.GetUser("yourdomain","youruserName");
       
       if (user==null) return;
      
       var rolesList = user.Roles.ToList();

        foreach(var role in rolesList)
        {
            var roleName = role.DisplayName;
            var roleDomain = role.Domain;
            // you have all the properties of a role in role object
        }

To get a user by a username you can use :

 public class UserRepository
  {
       public static User GetUser(string domainName, string userName)
        {
          
          if (User.Exists(domainName + @"\" + userName))
            return User.FromName(domainName + @"\" + userName, true);
          return null;
        }
    }

To get a user roles you can use

       Sitecore.Security.Accounts.User user = UserRepository.GetUser("yourdomain","youruserName");
   
       var rolesList = user.Roles.ToList();

        foreach(var role in rolesList)
        {
            var roleName = role.DisplayName;
            var roleDomain = role.Domain;
            // you have all the properties of a role in role object
        }

To get a user by a username you can use :

 public class UserRepository
  {
       public static User GetUser(string domainName, string userName)
        {
          
          if (User.Exists(domainName + @"\" + userName))
            return User.FromName(domainName + @"\" + userName, true);
          return null;
        }
    }

To get a user roles you can use

       Sitecore.Security.Accounts.User user = UserRepository.GetUser("yourdomain","youruserName");
       
       if (user==null) return;
      
       var rolesList = user.Roles.ToList();

       foreach(var role in rolesList)
        {
            var roleName = role.DisplayName;
            var roleDomain = role.Domain;
            // you have all the properties of a role in role object
        }
Source Link
Vlad Iobagiu
  • 18.8k
  • 2
  • 27
  • 53
Loading