快捷方式Microsoft身份验证

时间:2016-01-07 23:41:49

标签: asp.net-core asp.net-core-mvc entity-framework-core asp.net-identity-3

我们正在尝试使用ASP.NET 5 Web应用程序模板向我们的应用程序引入Microsoft身份验证。

默认模板将用户从_LoginPartial.cshtml中的登录链接带到登录页面,在该页面中,用户可以选择其首选身份验证提供程序。我们只想接受Microsoft身份验证,因此我们希望_LoginPartial.cshtml将用户登录。

我修改了_LoginPartial.cshtml

<ul class="nav navbar-nav navbar-right"> @*<li><a asp-controller="Account" asp-action="Register">Register</a></li>*@ <li><a asp-controller="Account" asp-action="ExternalLogin">Log in</a></li> </ul>

我还更改了AccountController ExternalLogin

的提供程序参数
        public IActionResult ExternalLogin(string provider="Microsoft", string returnUrl = null)
    {
        // Request a redirect to the external login provider.
        var redirectUrl = Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl });
        var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
        return new ChallengeResult(provider, properties);
    }

但在我的情况下ExternalLogin未被调用且空白页

http://localhost:52711/Account/ExternalLogin已退回。

我做错了什么?

1 个答案:

答案 0 :(得分:0)

我通过用表格

替换登录链接按钮解决了这个问题
    <form asp-controller="Account" asp-action="ExternalLogin" method="post" asp-route-returnurl="@ViewData["ReturnUrl"]" class="navbar-right">
    <button type="submit" class="btn btn-link navbar-btn navbar-link" name="provider" value="Microsoft" title="Log in">Log In</button>
</form>
相关问题