More in this section

Forums / Developing with Sitefinity / Getting UserID from telerik_Users

Getting UserID from telerik_Users

5 posts, 0 answered
  1. Himanshu Jain
    Himanshu Jain avatar
    5 posts
    Registered:
    06 Jul 2012
    04 Sep 2009
    Link to this post
    Hi,

    I am developing a user Control in administrator area, in which i need to store/retreive data from my own table. But my table consist a field CreatedBy, in which i have to store the Current UserID of the application

    For example : If i have logged in by "admin" account and perform some action and want to save some information in my table, then the UserID of "admin" User from "telerik_Users" table should be store in CreatedBy field of my table.

    So, my query is how to get the Current UserID in C# code???
    Is their any build-in way to get the Current UserID???

    Please suggest...

    Thanks in advance
    Himanshu Jain
  2. Nikolai
    Nikolai avatar
    216 posts
    Registered:
    01 Jun 2017
    04 Sep 2009
    Link to this post
    Hi Himanshu Jain,

    You can use the UserManager class and it's methods and properties to manage your users.
    For example you can use GetCurrentUser() method to get the current logged in user as IPrincipal object.

    Hope this helps.

    Greetings,
    Nikolai
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Himanshu Jain
    Himanshu Jain avatar
    5 posts
    Registered:
    06 Jul 2012
    04 Sep 2009
    Link to this post
    Hi Nikolai

    Thanks for your superfast support....

    I would try this on my next working day.
    I am sure, it will work,and in case of any issue, i will revert back to you.

    Thanks again
    Himanshu

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    06 Sep 2009
    Link to this post
    Hello Himanshu Jain,

    Below is the code that you should use.

            string userName = UserManager.GetCurrentUserName(); 
            MembershipUser myuser = Membership.GetUser(userName); 
            string myuserID = myuser.ProviderUserKey.ToString(); 
            Response.Write(myuser.UserName + "-" + myuserID); 


    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Himanshu Jain
    Himanshu Jain avatar
    5 posts
    Registered:
    06 Jul 2012
    07 Sep 2009
    Link to this post
    Hi Ivan,

    Thanks for the code itself, how nice you teleric guys are...

    Thanks again Mr. Dimitrov

Register for webinar
5 posts, 0 answered