简体   繁体   中英

How get logon username

string userName=System.Security.Principal.WindowsPrincipal(
    System.Security.Principal.WindowsIdentity.GetCurrent()).Identity.Name;

When debugging on my local PC, I get my Windows UserName, but when running on the server I get "NT AUTHORITY\\NETWORK SERVICE";

You should try setting the authentication mode to Windows in your configuration & also disable anonymous users in authorization tag. ( from a previous answer ):

To get the currently logged in user to a Windows account you have to use Windows authentication instead of Forms authentication :

In debug in local PC, get Windows UserName, but in server get "NT AUTHORITY\\NETWORK SERVICE";

It shows the application current user. When you host your application on the Visual Studio web server it uses your local account. However, when you will log in to the web application with different credentials it will always show your current Windows login.

An application deployed to IIS uses the NT AUTHORITY\\SYSTEM account in your case.

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