如何通过匿名访问从ASP.NET获取windows登录用户id



我有一个web应用程序,它设置在表单和匿名访问上。我有一个默认页面,我想在上面获取当前windows登录用户,它是一个ASP.Net应用程序。

我该怎么做?

我相信您正在寻找HttpContext.User.Identity.Name

你好,您可以尝试使用此代码

   WindowsIdentity wi = WindowsIdentity.GetCurrent();
   var result = wi.Name;
   var anonymous = wi.IsAnonymous; //For ensure your authentification mode

你可以使用这个代码

System.Web.HttpContext.Current.User.Identity.Name

但您必须确保您已经在安全包(可能是httpmodule)的线程中添加了主体。(如果您有自定义身份验证和授权)

此代码有效:

        var w = WindowsIdentity.GetCurrent().Name;
        this.HttpContext.Trace.Warn(w);

最新更新