如何获得登录的用户当前的ID?如何获得、用户、ID

2023-09-09 21:10:20 作者:沉沦

我正在从ASP.NET Web应用程序模板构建了一个简单的项目(Web窗体,而不是MVC)。当用户登录时,我想要抓住用户的ID,并将其存储在一个会话变量,这样我就可以通过它的页面之间。如何获得用户从ASP.NET成员资格提供ID?通过用户的ID,我指的会员数据库的GUID。有没有一种方法来获取用户的ID?

I'm working on a sample project built from the ASP.NET Web Application template (web forms, not MVC). After a user logs in, I want to grab the user's ID and store it in a session variable so I can pass it between pages. How do I get the user's ID from the ASP.NET membership provider? By user's ID, I'm referring to the GUID in the membership database. Is there a method to get the user's ID?

我使用的是默认的数据库模式并将其部署到我的服务器。

I'm using the default database schema and have it deployed to my server.

谢谢!

推荐答案

试试这个:

MembershipUser membershipUser = Membership.GetUser();
string UserID = membershipUser.ProviderUserKey.ToString();