简体   繁体   English

如何从IIS中的Windows身份验证获取用户名输入?

[英]How to get username input from Windows Authentication in IIS?

In IIS I have the authentication set to Windows. 在IIS中,我将身份验证设置为Windows。

2 Questions: 2个问题:

  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: 要回答您的第一个问题,这是如何通过Windows身份验证访问用户:

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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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