【问题标题】:How to get username input from Windows Authentication in IIS?如何从 IIS 中的 Windows 身份验证获取用户名输入?
【发布时间】:2014-08-26 15:34:51
【问题描述】:

在 IIS 中,我将身份验证设置为 Windows。

2 个问题:

  1. 有没有一种方法可以在加载页面之前获取用户为该弹出式身份验证窗口输入的用户名和

  2. 有没有办法让他们每次访问页面时都需要登录?

谢谢。

【问题讨论】:

    标签: c# asp.net .net iis windows-server-2008


    【解决方案1】:

    要回答您的第一个问题,这是您如何通过 Windows 身份验证访问用户:

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

    还有其他选项,例如:

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

    或者

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

    【讨论】:

    • 任何主体或上下文都可以获取密码吗?
    • 不,密码不会重试,这是出于安全原因。
    • 好的。在我看来,只要用户至少登录一次,然后在他们的会话结束之前,它就会始终显示最近登录的上下文。这应该没问题,因为我只是想避免将运行默认应用程序池的进程的用户名返回用于存档目的。
    • 如果您担心这是主题或Authorization,可以使用以下授权配置元素在 web.config 中解决:<authorization><allow roles="Admins"/><deny users="*"/></authorization>
    猜你喜欢
    • 2020-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-09
    • 2019-01-09
    • 2020-12-21
    • 2010-10-10
    相关资源
    最近更新 更多