title: Owin: OnApplyRedirect called several times and Create incorrect RedirectUri
body: <p>I use <strong>CookieAuthentication</strong> in my application with owin and set redirect url on <code>OnApplyRedirect</code> like the following code:</p>
  
  <pre><code> app.UseCookieAuthentication(new CookieAuthenticationOptions
   {
       ExpireTimeSpan = TimeSpan.FromDays(30),
       AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
       LoginPath = new PathString("/account/sign-in"),
       //LogoutPath = new PathString("/account/log-out"),
       ReturnUrlParameter = "returnTo",
       CookieName = "BIR",
       Provider = new CookieAuthenticationProvider()
       {
           OnValidateIdentity = SmObjectFactory.Container.GetInstance&lt;IAppUserManager&gt;().OnValidateIdentity(),
           OnApplyRedirect = c =&gt;
           {
               if (!c.Request.IsAjaxCall())
               {
                   c.Response.Redirect(c.RedirectUri);
               }
           }
       }
   });
  </code></pre>
  
  <p>my problem is <code>c.RedirectUri</code> value, i set break point and trace my code after do this i understand that <code>OnApplyRedirect</code> <strong>called serveral time</strong>.</p>
  
  <p>In the First call <code>RedirectUri</code> is:</p>
  
  <blockquote>
    <p><code>http://localhost:7537/account/sign-in?returnTo=%2Fadmin-panel</code></p>
  </blockquote>
  
  <p>In the Second call <code>RedirectUri</code> is:</p>
  
  <blockquote>
    <p><code>http://localhost:7537/account/sign-in?returnTo=%2Faccount%2Fsign-in%3FreturnTo%3D%252Fadmin-panel</code></p>
  </blockquote>
  
  <p>And more ...</p>
  
  <p>In pre call old url add in new url.
  I try to solve this problem, search and research in another and current site but do not find an answer, why <code>OnApplyRedirect</code> call several times?
  <code>Configuration</code> method in <code>Startup.cs</code> class Only once is called.
  other details :</p>
  
  <ul>
  <li>Owin version: 3.1.0</li>
  <li>ASP.NET MVC Version: 5.x </li>
  <li><p>Visual Studio Version: 2017 (15.2)</p>
  
  <p><a href="https://gist.github.com/SoheilAlizade/2acfb737092ed6641ae2b417e39a2b11" rel="nofollow noreferrer">Startup class in gist</a></p></li>
  </ul>