예제 #1
0
 /// <summary>
 /// Initializes the Identity database if it is not already initialized. If initialized, it binds the database to the application through dependency injection
 /// </summary>
 public static IApplicationBuilder InitializeIdentityDatabase(this IApplicationBuilder application, IHostingEnvironment hostingEnvironment, IdentityDatabaseContext identityContext)
 {
     if (hostingEnvironment.IsDevelopment())
     {
         IdentityDatabaseIntializer.InitializeDevelopmentEnvironment(identityContext);
     }
     else
     {
         IdentityDatabaseIntializer.InitializeProductionEnvironment(identityContext);
     }
     return(application);
 }
예제 #2
0
        /// <summary>
        /// Configures the application and HTTP request pipeline. Configure is called after ConfigureServices is
        /// called by the ASP.NET runtime.
        /// </summary>
        /// <param name="application">The application.</param>
        /// <param name="loggerfactory">The logger factory.</param>
        /// <param name="identityContext">The database context for the identity database</param>
        public void Configure(IApplicationBuilder application, ILoggerFactory loggerfactory,
                              IdentityDatabaseContext identityContext)
        {
            //__BEGIN_INITIALIZE_DATABASES_
            if (_hostingEnvironment.IsDevelopment())
            {
                IdentityDatabaseIntializer.InitializeDevelopmentEnvironment(identityContext);
            }
            else
            {
                IdentityDatabaseIntializer.InitializeProductionEnvironment(identityContext);
            }

            //__END_INTIALIZE_DATABASES_

            application
            // Removes the Server HTTP header from the HTTP response for marginally better security and performance.
            .UseNoServerHttpHeader()
            // Require HTTPS to be used across the whole site. Also set a custom port to use for SSL in
            // Development. The port number to use is taken from the launchSettings.json file which Visual
            // Studio uses to start the application.
            .UseRewriter(
                new RewriteOptions().AddRedirectToHttps(StatusCodes.Status301MovedPermanently, _sslPort))
#if (CORS)
            .UseCors(CorsPolicyName.AllowAny)
#endif
            .UseResponseCaching()
            .UseResponseCompression()
            .UseStaticFilesWithCacheControl(_configuration)
            .UseCookiePolicy()
            .UseIfElse(
                _hostingEnvironment.IsDevelopment(),
                x => x
                .UseDebugging()
                .UseDeveloperErrorPages(),
                x => x.UseErrorPages())
            .UseStrictTransportSecurityHttpHeader()
            .UsePublicKeyPinsHttpHeader()
            .UseContentSecurityPolicyHttpHeader(_sslPort, _hostingEnvironment)
            .UseSecurityHttpHeaders()
            .UseAuthentication()
            .UseMvc();
        }