I installed Identity Server4 which works fine. I use an application Asp.Net Core MVC as a client application. I have a login action and when the user click the button I want to redirect to the identity server login page but I dont know how to do it:
public IActionResult Login()
{
return <Redirect to identity server4 login page??? How to do?>
}
If I add an annotation with Authorized, it does it automatically:
[Authorized]
public IActionResult Login()
=> Work fine, it redirect to identity server login page with lots of information passed by url
How to do it manually?
You can return a ChallengeResult
from the action, using the Challenge
convenience method:
public IActionResult Login() =>
Challenge(new AuthenticationProperties
{
RedirectUri = "/"
});
This challenges using the default challenge scheme, which has already been set up in your example given that the [Authorize]
attribute is giving the desired result. The example above also demonstrates how to set the RedirectUri
.
To learn more about what challenge means, see What exactly does Challenge mean in Asp .Net Core 3?.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With