Nolram Atamrolf
Nolram Atamrolf

Reputation: 13

how can i get the userId or membershipId of the user that log in in asp.net mvc

I'm working on a Employer-worker website. My problem is whenever a specific employer is log in I want to filter all the position that certain employer have and put it in a dropdown. How can I get the userId of the current user for me be able to filter the position.

In the database of the employer I have a field named userId it a FK of the userId in my membershipId table.

I found this on the net:

Guid userGuid = (Guid)Membership.GetUser().ProviderUserKey;

But I can't understand how can I use or put this on my controller.

Upvotes: 1

Views: 99

Answers (2)

Damith
Damith

Reputation: 63065

You can use

User.Identity.Name

inside your controller

Upvotes: 0

Try this:

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

The way you found is also correct, but the questions in where you want to use this in controller.

Most common uses are like redirecting the users to the corresponding view, which is accessible to the current user.

Upvotes: 1

Related Questions