手动将MVC操作重定向到Identity Server 4登录页面

时间:2019-04-11 13:33:35

标签: c# asp.net-core identityserver4

我安装了工作正常的Identity Server4。我使用Asp.Net Core MVC应用程序作为客户端应用程序。我有一个登录操作,当用户单击按钮时,我想重定向到身份服务器登录页面,但我不知道该怎么做:

public IActionResult Login()
{
   return <Redirect to identity server4 login page??? How to do?>
}

如果添加带有“已授权”的注释,它将自动执行该操作:

[Authorized]
public IActionResult Login()
  => Work fine, it redirect to identity server login page with lots of information passed by url

如何手动进行?

1 个答案:

答案 0 :(得分:2)

您可以使用Challenge从操作中返回ChallengeResult

public IActionResult Login() =>
    Challenge(new AuthenticationProperties
    {
        RedirectUri = "/"
    });

这将使用默认的挑战方案进行挑战,在您的示例中已经设置了默认挑战方案,考虑到[Authorize]属性给出了理想的结果-它还演示了如何设置RedirectUri

以下是答案,说明了挑战的含义:What does "Challenge" term stand for?

相关问题