0

我們正在嘗試使用ASP.NET 5 Web應用程序模板將Microsoft身份驗證引入我們的應用程序。快捷方式Microsoft身份驗證

默認模板將用戶從_LoginPartial.cshtml的登錄鏈接轉到登錄頁面,在那裏他們選擇他們的首選身份驗證提供程序。我們只希望接受微軟認證,所以我們要_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被返回。

我在做什麼錯?

回答

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> 
更換登錄鏈接按鈕