Why is the Owin Startup class configuration method called before and after the page loads?

The OWIN startup class configuration method is called twice in the asp.net authentication application. The method is called twice, that is, before and after loading the page on the server side. I already found one question ( Why the method for setting the SignalR Startup class is called twice ), but it does not clarify me as to what is pre-initialization after the code is initialized. Why is this necessary and will it have any performance issues in my application?

Here's the code that runs twice:

 public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);
        }
    }

The following is the implementation of the configuration method:

 public void ConfigureAuth(IAppBuilder app)
    {
        // Configure the db context, user manager and signin manager to use a single instance per request
        app.CreatePerOwinContext(RavenContext.CreateSession);
        app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
        app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);

        // Enable the application to use a cookie to store information for the signed in user
        // and to use a cookie to temporarily store information about a user logging in with a third party login provider
        // Configure the sign in cookie
        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Account/Login"),
            Provider = new CookieAuthenticationProvider
            {
                // Enables the application to validate the security stamp when the user logs in.
                // This is a security feature which is used when you change a password or add an external login to your account.  
                OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                    validateInterval: TimeSpan.FromMinutes(30),
                    regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
            }
        });            
        app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
}
+4
source share
1 answer

, , , /preview, , .

F5, /preview, /, Startup.Configuration.

/preview , .

Startup, - , , .

public class Startup
{
    public static Guid GlobalGuid { get; private set; }

    static Startup()
    {
        GlobalGuid = Guid.NewGuid();
    }

    public void Configuration(IAppBuilder app)
    {           
       File.AppendAllLines(@"c:\temp\Startup.txt", 
                           new[] { DateTime.Now + " initialized - " + GlobalGuid });
    }
}
0

All Articles