简体   繁体   中英

How to get username input from Windows Authentication in IIS?

In IIS I have the authentication set to Windows.

2 Questions:

  1. Is there a way that I can grab the username that was entered by the user for that pop-up authentication window before it loads the page and

  2. Is there a way I can make it so that the login is required every time they visit the page?

Thanks.

To answer your first question this is how you access the user from a windows authentication:

WindowsPrincipal winPrincipal = (WindowsPrincipal)HttpContext.Current.User;

There are other options like:

WindowsIdentity winId = WindowsIdentity.GetCurrent();
WindowsPrincipal winPrincipal = new WindowsPrincipal(winId);

Or

WindowsPrincipal winPrincipal = (WindowsPrincipal) Thread.CurrentPrincipal();

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