更新时间:2022-05-14 23:30:44
环境.UserName [ ^ ]获取当前登录到Windows操作系统的用户的用户名-这是当前正在执行代码的安全证书的标识.
您想要的是 HttpContext.User [
Environment.UserName [^] Gets the user name of the person who is currently logged on to the Windows operating system - it''s the identification of the security credentials currently executing the code.
What you want is HttpContext.User[^] which will be the security credentials for the user executing the HTTP request.
HttpContext.Current.User.Identity.Name
试试...
try...
string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;