CurrentPrincipal.Identity.Name is blank

12.8k Views Asked by At

I'm trying to use System.Threading.Thread.CurrentPrincipal.Identity.Name to get the login of who is using an ASP.NET application. I'm not getting any build errors, but it returns a blank value. I'm using IIS 6 and here are my authentication settings:

  • Anonymous Authentication: Disabled
  • ASP.NET Impersonation: Disabled
  • Basic Authentication: Enabled
  • Windows Authentication: Enabled

I have no authorization settings in my Web.config file either. Here is the method I am using to try to get the login:

    public void SetUser()
    {
       string login = System.Threading.Thread.CurrentPrincipal.Identity.Name;
    }

I have a breakpoint to check the value and it says login = "".

How can I get the login?

EDIT

Here is my authentication picture:enter image description here

2

There are 2 best solutions below

2
On

I was able to fix it. In my project properties, I was using IIS express so my application wasn't hitting my actual IIS. I unchecked that, created a virtual directory and disabled all authentication except Windows Authentication and it works now.

2
On
Thread.CurrentPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());

Worked for me. I was having the same problem.