HttpContext.Current.User.Identity.Name returns DefaultAppPool,为什么?

HttpContext.Current.User.Identity.Name returns DefaultAppPool, why?

我正在尝试获取当前用户的 Windows 登录名,但它只是 returns DefaultAppPool(池 运行 网站)。如果我尝试在 web.config 中添加模拟,我会得到运行 IIS 的 Windows 用户。

IIS 配置启用了 Windows 身份验证并禁用了匿名身份验证。

如何让访问该网站的用户转为访问该网站?

string userName1 = HttpContext.Current.Request.LogonUserIdentity.Name;
string userName2 = User.Identity.Name;// don't take it from HttpContext

勾选您需要的是哪一个。第二个是页面的 属性 !

问题是额外的 Windows ID 存储在凭据管理器中,使我们的 PC 看起来像是服务器的用户已登录。

我的原始代码有效,只是看起来不像以前那样。