Jelle Jelle - 1 month ago 10
ASP.NET (C#) Question

Windows Authentication not working on server

I'm developing a website in ASP.NET and C#.

I've created the website so when a user goes to the site, his windows client username is read out with:

System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();


and then I lookup his username in the db and create a user object with all necessary data (team, name, permission level, role, ...) from the return data.
Then I keep this object in a session var until the user logs out.

This was working like a charm locally but now that I've deployed to the server I get
defaultAppPool
for every user.

What am I doing wrong?

In my web.config file I have:

authentication mode="Windows"


I have to admit this is the first time that I'm doing the deploying myself and everything went smoothly except for this.

Joe Joe
Answer Source

As you've discovered, System.Security.Principal.WindowsIdentity.GetCurrent() gives you the identity of the application pool.

You should be using HttpContext.Current.User.Identity.