简体   繁体   English

HTTPcontext没有返回正确的结果

[英]HTTPcontext not returning correct result

I am trying to fetch the current user name using HTTPcontext object using 我正在尝试使用HTTPcontext对象获取当前用户名

string username=HttpContext.Current.User.Identity.Name

but I am observing weird behavior ie when I load first time I get username as NT AUTHORITY\\IUSR but when I load second or third time I get the correct logged in username. 但是我观察到奇怪的行为,即,当我第一次加载时,我得到的用户名是NT AUTHORITY\\IUSR但是当我第二次或第三次加载时,我得到了正确的登录用户名。 Couldn't figure out why on first run correct username is not getting returned. 无法弄清楚为什么第一次运行时没有返回正确的用户名。

This ia actually a feature called ASP.NET Impersonation . 这实际上是一个称为ASP.NET模拟功能 which is enabled for your application. 已为您的应用程序启用。

In this instance, ASP.NET impersonates the token passed to it by IIS, which is either an authenticated user or the anonymous Internet user account (IUSR_machinename). 在这种情况下,ASP.NET会模拟IIS传递给它的令牌,该令牌可以是经过身份验证的用户,也可以是匿名Internet用户帐户(IUSR_machinename)。 That is what exactly happening to your application. 那正是您的应用程序正在发生的事情。 you can read about Impersonation and how to control it at MSDN . 您可以在MSDN上了解有关模拟的信息以及如何对其进行控制。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM