Get ASP.NET MVC Membership

I am writing a new application in ASP.NET MVC. I created my own MemberhipProvider that stores membership data in my own db schema. It all works, but how do I get a member in my application so that I can get the user key of the logged in user and load the model classes related to this user?

+6
c # asp.net-mvc asp.net-membership
source share
2 answers

You can use the following:

using System.Web.Security; var user = Membership.GetUser(); 
+9
source share

Use the static Membership class to retrieve a user using GetUser . You need to configure the provider in the web.config file. When you log in, you get a username, presumably a text field in your form. After logging in, you can get it from the user property of the controller.

 string username = this.User.Identity.Name; MembershipUser user = Membership.GetUser( username ); 
+4
source share

All Articles