My legacy ASP.NET Framework 4.5 (Windows auth) web site running in IIS uses the following code to get the Windows user id (to assess permissions):
String Name = System.Environment.UserName;
Looking at a log of this string, the Windows user ID isn't obtained correctly; rather, the name corresponding to the application pool credentials is obtained.
Is this due to using impersonation in web.config
:
<identity impersonate="true" userName="app_user" password="xxxx" />
Or can I change a setting in IIS to correct this?
The web site used to work correctly. Something was changed in IIS and now it doesn't...
In web.config, windows authentication is specified:
<system.web>
<compilation debug="true" defaultLanguage="c#" targetFramework="4.5" />
<authentication mode="Windows" />. . .
UPDATE: by enabling Anonymous Authentication (impersonation) in IIS for the web application itself, I was able to overcome this issue.