Using session variable with ASP.Net membership provider

时间秒杀一切 提交于 2019-12-02 20:43:41

问题


I m using the Asp.net membership provider with my web application !

I would like to know how to get the user ID and How and Where can I add code to the application to set same session variable On the User log on ! This is the scenario : The user Logon, I catch his ID an the database I execute some query to set same session variable with data in relation with this user : Like name and other stuff from other table in relation with the user table ! According to user data(role and other stuff), I redirects it to his own view or page.

Thank you for helping me !

PS :The membership system are using his own database : ASPNETDB.mdf ! PSS: I m using C sharp !


回答1:


Membership.GetUser().ProviderUserKey is what you're looking for. Why do you want to store it in Session?




回答2:


Are you saying that you want to store the Username in the Session rather than the user key from the membership database?

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

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


来源:https://stackoverflow.com/questions/3623777/using-session-variable-with-asp-net-membership-provider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!