获取当前Windows用户的名称,并返回"IIS APPPOOL/Sitename". [英] Getting the name of the current Windows user returning "IIS APPPOOL/Sitename"

查看:139
本文介绍了获取当前Windows用户的名称,并返回"IIS APPPOOL/Sitename".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一生都无法解决这个问题.我正在尝试使用以下行获取登录到Windows的当前用户的名称:

I can't figure this out for the life of me. I'm trying to get the name of the current user logged onto Windows using the following line:

string user = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();

当我通过IIS发布并打开它后运行此行时,它给我起了一个名称"IIS APPPOOL/SiteName".但是,当我通过Visual Studio 2013调试器运行此命令时,将显示正确的名称.

When I run this line after publishing and opening it through IIS, it gives me a name of "IIS APPPOOL/SiteName". However, when I run this through the Visual Studio 2013 debugger, the correct name appears.

推荐答案

基于我在具有Windows身份验证的IIS下的测试,该测试仅在web.config上启用而不能模拟; System.Web.HttpContext.Current.User.Identity.Name;返回我当前的登录用户而不是应用程序池用户,而System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString()返回应用程序池用户.

Base on my test under IIS having Windows Authentication only enable and not impersonation on the web.config; System.Web.HttpContext.Current.User.Identity.Name; return to me the current login user not the application pool user and System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString() return the application pool user.

我再次尝试,让他关注配置文件:

I tried again and having he following on the config file:

    <system.web>
       <authentication mode="Windows" />
   </system.web>

对于System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString(),我得到了:

Office \ atorr

Office\atorr

这是我的登录帐户

对于System.Web.HttpContext.Current.User.Identity.Name;我知道

IIS APPPOOL.NET v4.5经典版

IIS APPPOOL.NET v4.5 Classic

这是应用程序池正在运行的帐户.

which is the account the application pool is running.

这篇关于获取当前Windows用户的名称,并返回"IIS APPPOOL/Sitename".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆