none
Owin Middleware Delays Controller Actions RRS feed

  • Question

  • I have developed a web site using Owin Security as middleware and using its Cookie Authentication. It is working fine on my local laptop (Windows 10) but when I deploy it to a Windows Server (2019), it is extremely slow. If I comment out the Owin Authentication (part of the codes listed below) from the Startup class, the response is fine but since this is not okay as I need to have authentication. Based on the log file content I program to generate, it looks like every time when I clicked on a link on a page, it delays about 30 seconds before my controller action kicks off - no matter what the controller action does, the delay is about the same. Anybody knows what causes the delay? I suspect it is the Owin Middleware but it is working fine on my laptop, which tells me something is wrong on the server too. Could you offer some hints as to where I should look into? Thanks!!

    BTW - I also have a Web API web site on the same server and it also uses the OWIN Auth but the token authentication. The web api web site seems working fine and it is very responsive. 

                app.CreatePerOwinContext(ApplicationDbContext.Create);
                app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
                app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);

                System.Web.Helpers.AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.NameIdentifier;
                app.UseCookieAuthentication(new CookieAuthenticationOptions
                {
                    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                    LoginPath = new PathString("/Account/Login"),
                    Provider = new CookieAuthenticationProvider
                    {
                        OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                            validateInterval: TimeSpan.FromMinutes(30),
                            regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                    }
                });
                app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

    Thursday, September 19, 2019 11:06 PM

Answers

  • Hi Sam323,

    Welcome to MSDN forum.

    Not sure if it is useful, we recommend you could set queue number to bigger number(1000 to 5000) for your in application pool.

    And I found a similar issue at stack overflow: OWIN Login slow performance >30 Seconds, hope it could help you.

    BTW, since this forum is discussing about visual studio extension, we recommend you could redirect to ASP.NET forum, then you could get dedicated support about it.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    • Marked as answer by Sam323 Monday, September 23, 2019 3:34 PM
    Friday, September 20, 2019 7:17 AM

All replies

  • Hi Sam323,

    Welcome to MSDN forum.

    Not sure if it is useful, we recommend you could set queue number to bigger number(1000 to 5000) for your in application pool.

    And I found a similar issue at stack overflow: OWIN Login slow performance >30 Seconds, hope it could help you.

    BTW, since this forum is discussing about visual studio extension, we recommend you could redirect to ASP.NET forum, then you could get dedicated support about it.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    • Marked as answer by Sam323 Monday, September 23, 2019 3:34 PM
    Friday, September 20, 2019 7:17 AM
  • Hi Dylan, 

    Thank you for your reply. I found my own solution - oh well, workaround.

    I programmed my own customized cookie authentication provider which use my web api to validate the users. The authentication provider provided in the VS template uses a SQL local DB. Though I tried to override some of the functions to connect to my web api instead of the local DB, I think I failed to override them all and there must still be some functions that go to the SQL local DB which does not exist. So instead of trying to figure out what all those functions are, I just programmed my own customized provider. It is working without delay now.

    I worked my whole Thursday night for that and did not check back. Now I see the link you provided and it kind of verifies what I suspected. That link is actually for token authentication. I use token authentication for my web api which has been working for a while. I did not have the issue that user had. 

    I tried to find the best forum for this question. Since this is the only forum that mentions security, I placed it here. It seems the ASP.NET forum only deals with programming. 

    Anyway, I appreciate your reply and I will mark yours as the answer. 

    Thanks, 

    Sam

    Monday, September 23, 2019 3:33 PM