Get Login User Id

Asked

Viewed 1,187 times

3

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

Trying to explain better. I have an action called Criapub, which allows the user to write their publications on the site. In my publications table, has the user id, which is mandatory, for me to know who published on the site. My idea, is when the user click to create publications, this field of the table publications, receive the Id of the user logged in, thus allowing the.

  • I believe this can help: http://stackoverflow.com/a/25453584/2263584 Although . NET is already in version 4.5, I think this should still work.

  • @Tiagosilva I’m using Membership.

1 answer

0


As in this reply in Soen: get-the-id-of-the-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 so:

string userId = Membership.GetUser().ProviderUserKey.ToString();
  • I must implement this in the correct membershipuser getuser() method?

  • I get it. Just one more question, one of the parameters of this method is bool user online, or something like that. What do I do with it? It is necessary to implement it?

  • Hi. I’m sorry it took me so long to respond. Check to see if that’s it, please. public override Membershipuser Getuser(string username, bool userIsOnline){ string userid = Membership.Getuser().ProviderUserKey.Tostring(); } What would be the return of this method?

  • Make it clear now.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.