如何通过匿名访问从ASP.NET登录用户ID的Windows

时间:2012-08-01 08:04:05

标签: c# asp.net

我有一个在表单和匿名访问上设置的Web应用程序。我有一个默认页面,我想让用户登录当前的Windows,这是一个ASP.Net应用程序。

我该怎么做?

3 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

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

   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。 (如果您有自定义身份验证和授权)

答案 2 :(得分:0)

此代码有效:

        var w = WindowsIdentity.GetCurrent().Name;

        this.HttpContext.Trace.Warn(w);