By default "Global Administrators" will only have access to this impersonation feature. If you are impersonating a user that has access to CMSDesk, simply click the dropdown arrow and click Cancel Impersonation and it will log you back in.
If not here is some custom web part code I created to do the impersonation. When its complete it displays a "welcome <username> floated left and a sign in/out button floated right. To the left of the username is that dropdown arrow for impersonation:
<%@ Register Src="~/CMSAdminControls/UI/UniSelector/UniSelector.ascx" TagName="UniSelectorControl" TagPrefix="cms" %>
<div id="membership" class="row">
<div class="first six columns">
<asp:Label ID="lblLabel" runat="server" CssClass="CurrentUserLabel" EnableViewState="false" />
<asp:Literal ID="ltrSignLink" runat="server" EnableViewState="false" />
<asp:PlaceHolder runat="server" ID="pnlUsers" Visible="false">
<div class="hide">
<cms:UniSelectorControl ID="ucUsers" ShortID="us" ObjectType="CMS.User" runat="server"
ReturnColumnName="UserName" SelectionMode="SingleButton" IsLiveSite="false" DisplayNameFormat="##USERDISPLAYFORMAT##" />
</div>
<cms:ContextMenuContainer runat="server" ID="menuCont">
<asp:ImageButton runat="server" ID="imgImpersonate" />
</cms:ContextMenuContainer>
<cms:CMSUpdatePanel runat="server" ID="pnlHiddenImpersonate">
<ContentTemplate>
<asp:Button ID="btnHiddenImpersonate" runat="server" OnClick="btnHiddenImpersonate_Click" />
</ContentTemplate>
</cms:CMSUpdatePanel>
</asp:PlaceHolder>
</div>
<div class="last six columns textRight">
<div class="lastlogin">
<asp:Literal ID="litLastLogin" runat="server" EnableViewState="false" />
</div>
<cms:CMSButton ID="btnSignOut" runat="server" OnClick="btnSignOut_Click" CssClass="signoutButton" EnableViewState="false" />
<asp:LinkButton ID="btnSignOutLink" runat="server" OnClick="btnSignOut_Click" CssClass="signoutLink" EnableViewState="false" />
</div>
</div>
There are two methods you need to have. This one will be called in the protected override void OnLoad(EventArgs e) method every time the page is loaded.
private void CheckUserImpersonate()
{
CurrentUserInfo user = CMSContext.CurrentUser;
string originalUserName = "";
if (RequestHelper.IsFormsAuthentication())
{
originalUserName = ValidationHelper.GetString(SessionHelper.GetValue("OriginalUserName"), "");
}
else
{
originalUserName = ValidationHelper.GetString(SessionHelper.GetValue("ImpersonateUserName"), "");
}
// Show impersonate button for global admin only or impersonated user
if ((user.IsGlobalAdministrator) || (!String.IsNullOrEmpty(originalUserName)))
{
// only display the impersonate if in the "cards" section
pnlUsers.Visible = (CMSContext.CurrentDocument.NodeAliasPath.Contains("Cards"));
// Set context menu for impersonate
imgImpersonate.ImageUrl = GetImageUrl("~/App_Themes/MySite/Images/Misc/ArrowRed.png");
menuCont.MenuControlPath = "~/CMSAdminControls/ContextMenus/UserImpersonateMenu.ascx";
menuCont.MenuID = ClientID + "m_impersonate_context_menu";
menuCont.ParentElementClientID = ClientID;
menuCont.Parameter = "''";
menuCont.RenderAsTag = HtmlTextWriterTag.A;
menuCont.MouseButton = MouseButtonEnum.Both;
menuCont.VerticalPosition = VerticalPositionEnum.Bottom;
menuCont.HorizontalPosition = HorizontalPositionEnum.Left;
// Hide button for cancel impersonation
btnHiddenImpersonate.Style.Add("display", "none");
if (user.IsGlobalAdministrator || CMSContext.CurrentUser.IsInRole("KwikTripCreditDepartment", CMSContext.CurrentSiteName))
{
ucUsers.WhereCondition = "UserID IN (SELECT UserID FROM CMS_UserSite WHERE (UserIsGlobalAdministrator = 0)) AND (UserID != " + user.UserID + ") AND (UserName != N'public')";
pnlUsers.Visible = true;
}
else
{
// not needed
}
//Script for open uniselector modal dialog
string impersonateScript = "function userImpersonateShowDialog () {US_SelectionDialog_" + ucUsers.ClientID + "()}";
ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "ImpersonateContextMenu", ScriptHelper.GetScript(impersonateScript));
string userName = HttpUtility.UrlDecode(ValidationHelper.GetString(ucUsers.Value, String.Empty));
if (userName != String.Empty)
{
// Get selected user info
UserInfo iui = UserInfoProvider.GetUserInfo(userName);
SessionHelper.SetValue("OriginalUserName", CMSContext.CurrentUser.UserName);
SessionHelper.SetValue("OriginalUserNameHash", EncryptionHelper.EncryptData(SecurityHelper.GetSHA2Hash(CMSContext.CurrentUser.GetStringValue("UserPassword", ""))));
user.UserImpersonate(iui, ResolveUrl("~/Cards/My-Card/"));
}
// Set script for cancel impersonation only if original user name is specified
if (!String.IsNullOrEmpty(originalUserName))
{
string script = "function CancelImpersonation() {document.getElementById('" + btnHiddenImpersonate.ClientID + "').click();return false;}";
ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "CancelImpersonation", ScriptHelper.GetScript(script));
}
}
}
This method actually performs the impersonation.
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnHiddenImpersonate_Click(object sender, EventArgs e)
{
string originalUserName = ValidationHelper.GetString(SessionHelper.GetValue("OriginalUserName"), "");
if (RequestHelper.IsFormsAuthentication())
{
UserInfo ui = UserInfoProvider.GetUserInfo(originalUserName);
CMSContext.CurrentUser.UserImpersonate(ui, ResolveUrl("~/Cards/"));
}
else
{
SessionHelper.SetValue("ImpersonateUserName", null);
SessionHelper.SetValue("OriginalUserName", null);
CMSContext.CurrentUser.Invalidate(false);
// Log event
EventLogProvider log = new EventLogProvider();
log.LogEvent(EventLogProvider.EVENT_TYPE_INFORMATION, DateTime.Now, "Administration", "Impersonate", 0, null, 0, null, null, "User " + originalUserName + " has returned to his account.", CMSContext.CurrentSiteID, URLHelper.CurrentURL);
// send them back where they came from
URLHelper.Redirect(URLHelper.CurrentURL);
}
}
Hopefully this gets you going in the right direction.