问题描述
要在系统上获取当前登录的用户,请使用以下代码:
To get the current logged in user at the system I use this code:
string opl = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
我在需要此信息的ASP.NET应用程序上工作.因此,我将应用程序放在服务器上并尝试了上面的代码,并在字符串opl中获得了网络服务".我需要知道访问我的ASP.NET应用程序的PC的当前用户.
I work on an ASP.NET application where I need this information. So I've put my application on a server and tried the code above, and I get "Network Service" in the string opl. I need to know the current user of the PC who accesses my ASP.NET application.
推荐答案
如果您使用的是会员身份,则可以执行以下操作:Membership.GetUser()
If you're using membership you can do: Membership.GetUser()
您的代码正在返回分配有ASP.NET的Windows帐户.
Your code is returning the Windows account which is assigned with ASP.NET.
其他信息您将要包含System.Web.Security
Additional InfoYou will want to include System.Web.Security
using System.Web.Security
这篇关于如何获得正在访问ASP.NET应用程序的当前用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!