I have an asp.net core application with OpenID Connect authentication all working properly. The thing is, I want to redirect the client after a successful login, instead of using the callback url that is embedded in the state property in the querystring. How do I do that from the Client/Startup.cs?
In the code example below, say the user bookmarked or type in /home/Second, and after a successful login, I want to always redirect to /home/Index.
How do I do this?
[Authorize]
public class HomeController : Controller
{
public async Task<IActionResult> Index()
{
return View();
}
public async Task<IActionResult> Second()
{
return View();
}
}
You need something like:
services.AddAuthentication().AddOpenIdConnect(options =>
{
options.Events = new OpenIdConnectEvents
{
OnTicketReceived = ctx =>
{
// can be First, Second, Index, whatever
ctx.ReturnUri = "http://google.com";
return Task.CompletedTask;
}
}
}
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