简体   繁体   中英

Get current logged in user IIS returning DefaultAppPool

I have an asp.net application on my server that uses WindowsAuthentication to log in. The scenario is simple: users logged in, will use the same credentials to login the application.

Certainly, on IISExpress on my machine works great, but when I try to login the application on server, the current user returned is DefaultAppPool .

I guess it's a missing impersonate config on IIS. I tried to get the current user with:

string username = HttpContext.Current.Request.LogonUserIdentity.Name;
string username = WindowsIdentity.GetCurrent().Name;

... and all of above returns the current user loggedin but only works on IISExpress, but not on server IIS.

IIS Express config
DefaultAppPool
- Framework Version 4.0
- Application Pool Identity

Application Authentication Config
应用程序认证配置

Server Info
Windows 2008 R2 Enterprise
IIS 7.5

PD: Is not my best English

I had a similar issues; as far as I can tell it is because the web.config file needs to have the following entries:

<authentication mode="Windows" />
    <identity impersonate="true" />

Also in your IIS/Authentication section in Internet Information Services (IIS) Manager, make sure only Anonymous Authentication and Windows Authentication is Enabled. I had ASP.NET Impersonation checked by mistake and it was giving me the same error you described in this post. Once I disabled that (along with the other modifications), it seems to be working fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM