OWIN 混合身份验证 IIS 问题

OWIN Mixed Authentication IIS Issue

我有一个项目需要 Windows 身份验证和表单登录。我遇到了 OWIN Mixed Authentication 似乎符合我的要求。

在我自己的项目中实施之前,我尝试了 运行 来自源 link 的示例解决方案。

我使用 IIS Express 调试了解决方案,当我在 windows 身份验证对话框中输入我的凭据时,我在 logonUserIdentity 变量中找到了正确的凭据。

但是当我设置本地 IIS 站点时,添加设置以下功能委托 属性,如自述文件中所述:

Authentication - Windows to Read/Write  

当我在 windows 身份验证对话框中输入我的凭据时 NT AUTHORITY\IUSRlogonUserIdentity 变量而不是用户名中通过我进入了对话框。

我觉得发生这种情况是因为在 IIS 站点上启用了 AllowAnonymous 但它需要停止由于 CookieAuthentication 在 [=14] 中出现的登录循环=] class.

我应该如何设置我的 IIS 站点,以便 windows 凭据对话框通过输入的凭据而不是 NT AUTHORITY\IUSR。

I debugged the solution using IIS Express and when I entered my credentials into the windows authentication dialog my correct credentials where found in the logonUserIdentity variable.

据我所知,IIS express 使用当前计算机登录帐户作为匿名登录帐户。所以你会发现logonUserIdentity是对的。您可以尝试使用不同的域帐户登录应用程序。你会发现它仍然使用当前的计算机登录帐户,并没有更改为登录用户帐户。

由于mix auth允许多种登录方式,您应该始终启用匿名登录,让没有域帐户的人。

mix自己的auth使用asp.net身份外登陆实现用windows.The登陆asp.net身份外登陆会先去mixauth provider查windows验证结果。

如果成功,它将使用 windows 信息返回到帐户控制器的 ExternalLoginCallback 方法,并使用此信息生成身份用户。

在我看来,如果您想获取用户的当前登录信息,我建议您可以尝试使用会话在 ExternalLoginCallback 方法中存储 windows 用户帐户中的登录信息。

更多详情,您可以参考以下代码:

    [AllowAnonymous]
    public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
    {

        var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();

        Session["LoginonUsername"] = loginInfo.DefaultUserName;
        if (loginInfo == null)
        {
            return RedirectToAction("Login");
        }

        // Sign in the user with this external login provider if the user already has a login
        var result = await SignInManager.ExternalSignInAsync(loginInfo, isPersistent: false);
        switch (result)
        {
            case SignInStatus.Success:
                return RedirectToLocal(returnUrl);
            case SignInStatus.LockedOut:
                return View("Lockout");
            case SignInStatus.RequiresVerification:
                return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = false });
            case SignInStatus.Failure:
            default:
                // If the user does not have an account, then prompt the user to create an account
                ViewBag.ReturnUrl = returnUrl;
                ViewBag.LoginProvider = loginInfo.Login.LoginProvider;
                return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { Email = loginInfo.Email });
        }
    }

结果:

我的 IIS 站点绑定设置为 http://projectname

当我将 IIS 站点上的绑定更改为 http://localhost or http://pcname 时,它允许我通过正确的 windows 凭据。