简体   繁体   English

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

[英]HttpContext.Current.User.Identity.Name returns DefaultAppPool, why?

I'm trying to get the current user's Windows login but it just returns DefaultAppPool (the pool running the website). 我正在尝试获取当前用户的Windows登录名,但它只返回DefaultAppPool(运行网站的池)。 If I try and add impersonate in the web.config, I get the Windows user that runs IIS. 如果尝试在web.config中添加模拟,则将得到运行IIS的Windows用户。

IIS configuration has Windows authentication enabled and anonymous authentication disabled. IIS配置启用了Windows身份验证,并且禁用了匿名身份验证。

How do I get the user, that's visiting the website, instead? 我如何获取正在访问网站的用户呢?

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

Check which one of this you need. 检查您需要哪一个。 Second one is property of the page ! 第二个是页面的属性!

The problem was that extra Windows IDs were stored in the Credential Manager making our PC look like the server's user was logged in. 问题在于,凭据管理器中存储了额外的Windows ID,使我们的PC看起来像服务器用户已登录。

My original code worked, it just didn't seem like it had been. 我的原始代码可以正常工作,但看起来似乎不是。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 模拟HttpContext.Current.User.Identity.Name - Mock HttpContext.Current.User.Identity.Name 更改HttpContext.Current.User.Identity.Name - Changing HttpContext.Current.User.Identity.Name 用户登录后更改HttpContext.Current.User.Identity.Name - Changing HttpContext.Current.User.Identity.Name after User is logged in HttpContext.Current.User.Identity.Name始终为null - HttpContext.Current.User.Identity.Name is always null 访问DbContext中的HttpContext.Current.User.Identity.Name - Accessing HttpContext.Current.User.Identity.Name in the DbContext HttpContext.Current.User.Identity.Name在.ashx处理程序中不起作用 - HttpContext.Current.User.Identity.Name not working in .ashx hander HttpContext.Current.User.Identity.Name无法转换 - HttpContext.Current.User.Identity.Name can't be converted HttpContext.Current.User.Identity.Name在Active Directory中的什么位置? - HttpContext.Current.User.Identity.Name where is it looking in Active directory? HttpContext.Current.User.Identity.Name在Default.cs中工作,但不在Global.asax中工作 - HttpContext.Current.User.Identity.Name working in Default.cs but not Global.asax 在Web Api 2中获取HttpContext.Current.User.Identity.Name null通过angular 4登录 - Getting HttpContext.Current.User.Identity.Name null in Web Api 2 log in through angular 4
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM