HttpContext.Current.User.Identity.Name在Default.cs中工作但不是Global.asax

时间:2014-07-19 09:30:27

标签: c# asp.net httpcontext

在我的ASP.NET应用程序中我使用windows auth作为唯一的auth方法。

我可以在default.cs中读取登录用户:

HttpContext.Current.User.Identity.Name

现在,在我的应用程序中插入更多页面之后,需要在每个页面上读取用户名。

所以我在Global.asax中解雇了它,但结果是NULL。

我的web.config:

<configuration>
  <system.web>
    <authentication mode="Windows" />
         <authorization>
             <deny users="?"/>
          </authorization> 
    </system.web> 
</configuration>

有什么想法吗?

-pic

1 个答案:

答案 0 :(得分:1)

您可以使用can Thread.CurrentPrincipal.Identity.Name,也可以在Application_BeginRequest()

中设置当前线程主体