Reputation: 8515
I'd like to use the default membership through EF. I will have pages displaying custom user information, so I'd like to use the UserId column of aspnet_Users (membeship provider) table as primary key for the user specific infromation table. I can see I have the access to m.UserName of the LogOnModel model class. e.g. in LogOn.cshtml:
@model CPoll.Models.LogOnModel
<div class="editor-label">
@Html.LabelFor(m => m.UserName)
</div>
but I don't have access to m.UserId out of the box. Can this be changed for my purpose ? Is the default membership provider suitable for this purpose (user custom info page) ? Thank you.
Upvotes: 1
Views: 689
Reputation: 30152
The userID is stored here:
Membership.GetUser().ProviderUserKey.ToString();
If you want access to it, store it in a view model and reference it. BUT!!!! - I would not use it on the page though since you should be using this to change the user's info when they post BACK to the controller. Determine who they are from the provider and do not trust what was entered on the form as they could easily forge this to overwrite another user as I do in this demo in the Information Tampering Section
http://channel9.msdn.com/Events/TechEd/NorthAmerica/2011/DEV333
Upvotes: 2