Using a Session Variable with an ASP.Net Membership Provider

I am using Asp.net Membership Provider with my web application!

I would like to know how to get the user ID and how and where I can add code to the application to set the same session variable. The user log is turned on! This is the scenario: User Logon, I will catch his database identifier I execute some query to set the same session variable with data in relation to this user: like the name and other materials from another table in relation to the user table! According to user data (roles and other materials), I redirect it to my view or page.

Thanks for helping me!

PS: The membership system uses its own database: ASPNETDB.mdf! PSS: I use C sharp!

0
source share
2 answers

Membership.GetUser().ProviderUserKey- this is what you are looking for. Why do you want to keep it in a session?

+1
source

Are you saying that you want to save the username in the session, and not the user key from the membership database?

I had the same problem, you cannot get it from Membership objects. You need to save it when the user logs in. If you use the asp: Login control, you can add it to the repository using the OnLoggedIn event:

protected void OnLoggedIn(object sender, EventArgs e) 
{
    Session["username"] = Login1.UserName;
}
+1
source

All Articles