Get logged in user id

3

How do I get the user ID logged into the site, then insert it into another table?

Trying to explain better. I have an action called CreatePub, which allows the user to write their publications on the site. In my publications table, you have the user id, which is mandatory, for me to know who posted on the site. My idea, it's time for the user to click create publications, this field of the publications table, receive the user id logged in, thus allowing the insert.

    
asked by anonymous 03.10.2014 / 04:20

1 answer

0

How this answer in SOen: get-the-id-of-current-user-asp-net-membership

For a random user you need, do so:

MembershipUser mu = Membership.GetUser("username");
string userId = mu.ProviderUserKey.ToString();

For a logged-in user, you can do this:

string userId = Membership.GetUser().ProviderUserKey.ToString();
    
03.10.2014 / 18:40