More in this section

Forums / Developing with Sitefinity / UserManager returning incorrect user

UserManager returning incorrect user

2 posts, 0 answered
  1. Garry
    Garry avatar
    52 posts
    04 Nov 2010
    17 Aug 2010
    Link to this post
    I have a very simple control that generates a button with a url based off of teh currently logged in user and some other information. The issue I am seeing though is that the button works 85% of the time, but occassionally it will generate a URL for a totally different user. Am I not using the UserManager correctly or is there a better way to generate this URL?

    The code for the button is below.


    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="JitBitButton.ascx.cs" Inherits="JitBitButton"  %>
    <asp:HyperLink ImageUrl="~/JitBitButtonModule/Images/JitBitButton.png" ID="btnJitBit" runat="server" target="_blank" />

    using System;
    using System.Security.Cryptography;
    using System.Text;
    using System.Web;
    using Telerik.Security;
    public partial class JitBitButton : System.Web.UI.UserControl
        #region Properties
        /// <summary>
        /// Gets or sets the url of the page which contains SingleContact control,
        /// which will display full info on a single contact
        /// </summary>
        #region Event handlers    
        protected void Page_Load(object sender, EventArgs e)
            if (HttpContext.Current.User.Identity.IsAuthenticated)
                btnJitBit.NavigateUrl = CreateMD5HashURL();
                btnJitBit.NavigateUrl = "";
        private string CreateMD5HashURL()
            string userName = UserManager.GetCurrentUserName();
            string email = userName + "";
            string sharedKey = "fakeKey";
            string full = userName + email + sharedKey;
            full = full.Trim();
            // step 1, calculate MD5 hash from input
            MD5 md5 = System.Security.Cryptography.MD5.Create();
            byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(full);
            byte[] hash = md5.ComputeHash(inputBytes);
            // step 2, convert byte array to hex string
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < hash.Length; i++)
            string hashcode = sb.ToString();
            return "" + userName + "&email=" + email + "&userHash=" + hashcode;

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    12 Sep 2017
    17 Aug 2010
    Link to this post
    Hello Garry Clark,

    Instead of using HttpContext.Current.User.Identity.IsAuthenticated you could try using RolePrincipal principal = context.User as RolePrincipal, then check whether principal.Identity.IsAuthenticated

    I do not see any issue with UserManager.GetCurrentUserName();This returns principal.Identity.Name

    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered