如何获得登录的用户当前的ID? [英] How do I get the ID of the current logged in user?
本文介绍了如何获得登录的用户当前的ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从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();
这篇关于如何获得登录的用户当前的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文