简体   繁体   中英

Environment.UserName not working after hosting on IIS. Code with ASP.net core 2.0

Validating the use with Active directory using (System.DirectoryServices.AccountManagement) library. How can identify a user to make him auto-login. I was getting username using environment variable (Environment.UserName) at local run. However, fail to get the username after hosting on IIS Enviroment.Username is not working on IIS.

在此处输入图像描述

Environment.Username return the user on current thread of your asp.net application. That's why you get application pool identity instead of login user when you deploy it to IIS.

If you want IIS return the similar result, you could specify the user in the application pool identity of your asp.net core application. Then Environment.Username will return the similar result.

https://docs.microsoft.com/en-us/iis/manage/configuring-security/application-pool-identities

If the username is not what you want, you just want the application to handle client's user identity. You should enable IIS windows authentication. Then you will receive identity from Httpcontext.

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