简体   繁体   English

asp.net会员资格获取登录名

[英]asp.net membership get login name

我看到可以打电话给Request.IsAuthenticated,但是一旦登录,我如何从asp.net成员资格提供者那里获取登录名?

There's a number of mechanisms to get the currently logged on user's name, for example, you can get to it via the context of the current web page like so: 有很多机制可以获取当前登录的用户名,例如,您可以通过当前网页的上下文来访问它,如下所示:

Page.User.Identity.Name

However, usually the best way to get the current user's name is via the context of the current Http request like so: 但是,通常,获取当前用户名的最佳方法是通过当前Http请求的上下文,如下所示:

HttpContext.Current.User.Identity.Name

Ultimately, you're calling down into the same "User" object, and accessing the same System.Security.Principal.IIdentity object instance in either case, but using the HttpContext allows this code to be used not only in web pages but also ASP.NET user controls and POCO classes etc. 最终,无论哪种情况,您都需要调用相同的“ User”对象,并访问相同的System.Security.Principal.IIdentity对象实例,但是使用HttpContext不仅可以在网页中使用此代码,还可以在ASP中使用此代码。 .NET用户控件和POCO类等

Page.User.Identity.Name

尝试

Request.LogonUserIdentity

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM