3

I've created a custom pipeline to process the login to sent 2FA token. But somehow the pipeline is triggered twice. It doesn't happen with LoggingInProcessor (Used before Sitecore 9). Anyone know why? Currently, I'm using Sc 9.1 with IdentityServer.

Here's a quick description of the code

Config patch:

 <sitecore role:require="Standalone or ContentManagement">
    <pipelines>
      <owin.cookieAuthentication.signIn>
        <processor resolve="true" type="Mydll.MySignInPipeline, Mydll"
                        patch:after="processor[@type='Sitecore.Owin.Authentication.Pipelines.CookieAuthentication.SignIn.UpdateUserProperties, Sitecore.Owin.Authentication']"/>
      </owin.cookieAuthentication.signIn>

      <owin.cookieAuthentication.signedIn>
        <processor resolve="true" type=" Mydll.Mypipeline, Mydll"
           patch:before="processor[@type='Sitecore.Owin.Authentication.Pipelines.CookieAuthentication.SignedIn.CreateTicket, Sitecore.Owin.Authentication']"/>
        <processor resolve="true" type="Mydll.Mypipeline, Mydll"
              patch:before="processor[@type='Sitecore.Owin.Authentication.Pipelines.CookieAuthentication.SignedIn.CreateTicket, Sitecore.Owin.Authentication']"/>
        <processor resolve="true" type="Mydll.Mypipeline, Mydll"
              patch:before="processor[@type='Sitecore.Owin.Authentication.Pipelines.CookieAuthentication.SignedIn.CreateTicket, Sitecore.Owin.Authentication']"/>
      </owin.cookieAuthentication.signedIn>
    </pipelines>
  </sitecore>

MySignInPipeline is triggered twice, right after I click the Login, then right after It redirect to a new page (any pages) but before page load (Before on load)

I've tried reorder pipeline position but no luck.

Update

I was using WebUtil.Redirect(). But when I change it to Http.Response.Redirect("/redirectpath/",false) it's fixed. Found out that WebUtil.Redirect() always set it true :

public static void Redirect(string path, bool allowSame)
        {
            Assert.ArgumentNotNull(path, "path");
            HttpContext current = HttpContext.Current;
            if (current != null && (allowSame || !WebUtil.IsOnPage(path)))
            {
                current.Response.Redirect(path, true);
            }
        }

. But idk why, maybe anyone here can explain?

  • The server you are having this issue on, what is its defined Role? – vandsh Apr 25 at 18:30
  • Ermm not sure. I just follow what Sitecore do with their own patches. But I think it's not affected this pipeline. – Dika Purnasucita Apr 26 at 3:57
2

If you issued a redirect with second parameter being default, true, this explains it.

What happens in default is, the redirect gets called and then throws an exception to stop further processing. Which, in your case, means that after your processor runs - you abort the pipeline and Sitecore's OWin processing steps are never run.

See: Why Response.Redirect causes System.Threading.ThreadAbortException?

  • Hi Mark, thanks for your answer. I've tried using sitecore's WebUtil.Redirect(url,bool) with both true and false but seems no effect. Then I tried with Response.Redirect instead and set it to false and it works. As your answer, then why in the second run it's working? – Dika Purnasucita Apr 30 at 11:50
  • Right. Which is what I'm telling you. When you set it to false, the ThreadAbortException doesn't get thrown and the pipeline is able to finish as intended. So just do it like that. – Mark Cassidy Apr 30 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.