asp.net会员获取登录名

时间:2021-07-08 16:49:36

i see i can call Request.IsAuthenticated but how do i get the login name from asp.net membership provider once i am logged in?

我看到我可以调用Request.IsAuthenticated但是我如何在登录后从asp.net会员提供商处获取登录名?

3 个解决方案

#1


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类等。

#2


Page.User.Identity.Name

#3


try

Request.LogonUserIdentity

#1


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类等。

#2


Page.User.Identity.Name

#3


try

Request.LogonUserIdentity