Home > C#, Sitecore 6 > Virtualuser in Sitecore 6

Virtualuser in Sitecore 6

As promised a followup to virtualusers in sitecore.

This time for sitecore 6. The changes in the security model made to sitecore 6 makes only minor changes in the creation of the virtualusers. One of these changes are that the domain is set in the username.

using Sitecore.Data;
using Sitecore.Security.Authentication;
using Sitecore.Shell.Applications.ContentEditor.Gutters;

public class User {
private readonly Sitecore.Security.Accounts.User _userItem;

public User(string userName, bool isAdministrator)    {
//make sure that the username i prefixed with "sitecore"
//this sets the domain for the
userName = "sitecore\\"+userName
_userItem = AuthenticationManager.BuildVirtualUser(userName, true);
//Sitecore 6 needs profile settings for useritem
_userItem.Profile.Initialize(userName, true);
_userItem.Profile.Email = userName + "@something.dk";
_userItem.Profile.IsAdministrator = isAdministrator;
//save the useritem

public bool Login()    {
bool loginResult = AuthenticationManager.Login(_userItem.Name);
//Used for setting the show locked item in the gutter
ID gID = new ID("{1A005ECC-65B4-4A00-88BE-A6FA7D64BEA3}");
//Id for showing all locked items
return loginResult;

Categories: C#, Sitecore 6 Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: