I have a ASP.NET website that requires my App Pool be the Classic .Net App Pool. The site is running on .NET 3.5 on IIS 7. When I try to get the Active Directory User name of the logged in user:
System.Security.Principal.WindowsIdentity.GetCurrent().Name
I get the following:
IIS APPPOOL\Classic .NET AppPool
However when I set the app pool to .net 4.0 it returns the logged in username (which is what I want). Am I missing a setting?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
First of all put this lines inside web.config configuration section:
<authentication mode="Windows"/> <authorization> <deny users="?"/> </authorization> <identity impersonate="true"/>
Second go to IIS manager open your web app properties and check following settings for Authentication:
Anonymous Authentication = Disabled,
ASP.NET Impersonation = Enabled (this is not realy required),
Windows Authentication = Enabled
This settings will give you Active Directory User and also impersonate it.
Method 2
If the same code is being used and it works in one application pool and not the other, I would check the application pool’s settings. Look for the Identity attribute. I imagine, under the .NET 4.0 pool, you’ll have ApplicationPoolIdentity and under the 3.5, you have a hard coded account.
Edit
So it sounds like you aren’t really getting the users credentials. Of course you get the Domain account when you run locally….the process is running under you credentials. But when you run on another machine, it is running under the credentials of the account that processes the request…until you tell it to impersonate the user. And even then, you may have to set up Windows Authentication for the site to grab the credentials or use forms authentication with an AD hook to get everything under the current user account.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0