Owin: OnApplyRedirect called several times and Create incorrect RedirectUri

Viewed 1345

I use CookieAuthentication in my application with owin and set redirect url on OnApplyRedirect like the following 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<IAppUserManager>().OnValidateIdentity(),
         OnApplyRedirect = c =>
         {
             if (!c.Request.IsAjaxCall())
             {
                 c.Response.Redirect(c.RedirectUri);
             }
         }
     }
 });

my problem is c.RedirectUri value, i set break point and trace my code after do this i understand that OnApplyRedirect called serveral time.

In the First call RedirectUri is:

http://localhost:7537/account/sign-in?returnTo=%2Fadmin-panel

In the Second call RedirectUri is:

http://localhost:7537/account/sign-in?returnTo=%2Faccount%2Fsign-in%3FreturnTo%3D%252Fadmin-panel

And more ...

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 OnApplyRedirect call several times? Configuration method in Startup.cs class Only once is called. other details :

1 Answers
Related