Search code examples
c#openid-connectasp.net-core-2.1asp.net-core-middleware

How to redirect during OnTicketReceived


In our OIDC flow I have this method...

    options.Events.OnTicketReceived = async context =>
    {
      ...
        (bool doRedirect, string destUrl) = redirectHelper.ProcessRedirectionRules(user);
        if (doRedirect)
        {
          context.Response.Redirect(destUrl);
          return;
        }
      
      ...
    };

Unfortunately, though I really need to redirect the user to a destination URL, the context.Response.Redirect(destUrl); does not perform a redirection at all.

Am I attempting to redirect in the wrong place or in the wrong way? How should this be done?


Solution

  • I think you're missing this:

    if (doRedirect)
    {
      context.Response.Redirect(destUrl);
      context.HandleResponse();
      return;
    }
    

    Summary: Discontinue all processing for this request and return to the client. The caller is responsible for generating the full response.