Getting the name of the current Windows user returning “IIS APPPOOL/Sitename”

扶醉桌前 提交于 2019-11-29 14:05:27

you have to enable windows auth/impersonation on an ASP.NET site, else it will run in the context of the whatever account configured for the app pool.

https://msdn.microsoft.com/en-us/library/ff647405.aspx

 <system.web>
    ...
    <authentication mode="Windows"/>
    <identity impersonate="true"/>
    ...
 </system.web>

Base on my test under IIS having Windows Authentication only enable and not impersonation on the web.config; System.Web.HttpContext.Current.User.Identity.Name; return to me the current login user not the application pool user and System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString() return the application pool user.

Hope this help!

I've fiddled around with the config, IIS settings, and the string...but I think this line is what I needed to use:

string user = System.Web.HttpContext.Current.User.Identity.Name;

Seems to be returning a domain/username which I can use instead. Looks like an alternative solution.

All mentioned in other answers are true, PLUS THIS:

In IIS Manager, click Basic Settings.

In the Edit Application window click Connect as...

Choose Application User (pass through authentication). Do not use a specific user because that will be the identity detected.

Click on the project name and press F4 and it will open project properties window:

  1. Enable Windows authentication

  2. Disable anonymous authentication

  3. Add <identity impersonate="true"> in web.config

Now, deploy your code it should work fine.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!