且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在asp.net中获取当前的Windows用户?

更新时间:2021-09-13 08:27:30

假设您使用的是IIS 7.5,请执行以下操作。其他版本将类似。以上所有获取用户名的方式都应该有效。

Assuming you are using IIS 7.5 do the following. Other versions will be similar. All the above ways of getting the username should then work.

1) Double click on Authentication (This can be done at server level and your web site level so check both!)
2) Right click on Anonymous authentication and disable it and likewise enable Windows authentication
3) Click Basic settings. Check which application pool your website is using. Ensure it is using pass-through authentication for an "Application User" by clicking "Connect As" i.e. A user using a browser will be the person requesting authentication.
4) Click "Application Pools". Click the Application pool from (3). Click "Advanced Settings". Check the Identity is set to ApplicationPoolIdentity