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)
{
app.CreatePerOwinContext(RavenContext.CreateSession);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
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);
}
source
share