OWIN混合身份验证IIS问题

问题描述 投票:0回答:2

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

在实现我自己的项目之前,我尝试从源链接运行示例解决方案。

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

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

Authentication - Windows to Read/Write  

当我在Windows身份验证对话框中输入我的凭据时,NT AUTHORITY \ IUSR将通过logonUserIdentity变量而不是我在对话框中输入的用户名。

我觉得这发生了,因为在IIS站点上启用了AllowAnonymous,但是由于CookieAuthentication类中的Startup.Auth,它需要停止发生的登录循环。

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

iis owin forms-authentication windows-authentication mixed-authentication
2个回答
0
投票

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

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

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

混合使用auth使用asp.net身份外部登录来实现与windows的登录.asp.net身份外部登录将首先进入mixauth提供程序来检查windows auth结果。

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

在我看来,如果你想在用户中获得当前登录,我建议你可以尝试使用session来在用户帐户中以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 });
        }
    }

结果:

enter image description here


0
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.