How do I get the ID of the current logged in user?

喜你入骨 提交于 2019-12-05 12:37:51

Try this:

MembershipUser membershipUser = Membership.GetUser();
string UserID = membershipUser.ProviderUserKey.ToString();

You don't need passing user id around. Currently authenticated user is stored in HttpContext.Current.User.

you can define a static method in a class and use it:

public static Guid getCurrentUserGUID(){
    if (HttpContext.Current.User.Identity.IsAuthenticated)
    {
        MembershipUser myObject;
        myObject = Membership.GetUser(HttpContext.Current.User.Identity.Name);
        return (Guid)myObject.ProviderUserKey;
    }
    return Guid.Empty;       
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!