简体   繁体   中英

How to get windows logged in user id from ASP.NET with anonymous access

I have a web application which is set on forms and anonymous access. I have a default page on which I want to get the current windows logged in user, it's an ASP.Net application.

How can I do this?

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

Hello you can try with this code

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

You can use this code

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

But you must ensure that yo have added your principal in your thread in your security package, maybe httpmodule. (If you have custom authentification and Authorization)

This code works:

        var w = WindowsIdentity.GetCurrent().Name;

        this.HttpContext.Trace.Warn(w);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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