Ad

ASP.NET Forms Auth - Gettings User Data

- 1 answer

I'm using forms authentication on a very small ASP.NET web app (Web Forms) in which I want to store additional info about the user in a separate database table.

This is then linked back to the aspnet_User table and I was figuring the best column to link to is the UserId column. Problem is I can't work out how to get this piece of data when the user is logged in. Is it even possible?

Also, how do I get the email address?


Before someone points it out, I am aware of the ProfileProvider but the details stored need to be re-submitted each year (it's a registration application for a sporting club) and all previous data stored. So the ProfileProvider isn't really applicable (unless I'm wrong and it can be used to have it stored historically?).

Ad

Answer

here's how you can get the userid

MembershipUser myObject = Membership.GetUser();
string UserID = myObject.ProviderUserKey.ToString();
string Email = myObject.Email;
Ad
source: stackoverflow.com
Ad