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" />. . .
userName
andpassword
inidentity
tag. To configure an identity for the whole web application you should use application pool identity. To query the log on user information in your legacy ASP.NET web apps, usePage.User
orController.User
please. Don't know how you get started with this web app, but there are tons of samples over the internet telling the right way to go. – Lex Li