Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
932 views
in Technique[技术] by (71.8m points)

openid connect - ASP.NET Core 3.1 How can I redirect to the SignIn Action contained in the AccountController provided by MicrosoftIdentity

I have two login methods, OpenIDConnect and Cookie based Authentication.

I provide a button for the user to choose, and I have this code that then handles the request.

    using Microsoft.AspNetCore.Hosting;
    using Microsoft.Identity.Web.UI; 

    [HttpPost]
    [ValidateAntiForgeryToken]
    [AllowAnonymous]
    public async Task<IActionResult> LogIn(LogInModel model, string actionType)
    {
        if (actionType.Equals("AzureLogin")) {
            
            return RedirectToAction("SignIn", "AccountController", new { Area = "MicrosoftIdentity" });
        }
       // default Cookie Auth follows.
    }

When I redirect I am getting:

Status Code: 404; Not Found.

How can I invoke the provided SignIn Action. .NET Docs mention this, but I would prefer not to use the asp-controller property.

<li class="nav-item">
    <a class="nav-link text-dark" asp-area="MicrosoftIdentity" asp-controller="Account" asp-action="SignIn">Sign in</a>
</li>
question from:https://stackoverflow.com/questions/65949146/asp-net-core-3-1-how-can-i-redirect-to-the-signin-action-contained-in-the-accoun

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The name of the controller should be Account and not AccountController.

e.g.

return RedirectToAction("SignIn", "Account", new { Area = "MicrosoftIdentity" });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...