示例#1
0
文件: Startup.cs 项目: yonexbat/cran
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app,
                              IWebHostEnvironment env,
                              IAntiforgery antiforgery,
                              ILoggerFactory loggerFactory)
        {
            //Exception page
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                loggerFactory.AddFile("Logs/serilog-{Date}.txt");
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");

                //The HTTP Strict-Transport-Security response header (often abbreviated as HSTS)
                //lets a web site tell browsers that it should only be accessed using HTTPS, instead of using HTTP.
                app.UseHsts();
            }

            app.UseRouting();

            //Redirect to  HTTPS
            app.UseRewriter(new RewriteOptions().AddRedirectToHttps());

            //Add Seri Log
            loggerFactory.AddSerilog();

            //Static files
            app.UseDefaultFiles();
            app.UseStaticFiles();


            //Localization
            IOptions <RequestLocalizationOptions> options = app.ApplicationServices.GetService <IOptions <RequestLocalizationOptions> >();

            app.UseRequestLocalization(options.Value);

            //Security
            app.UseAuthentication();
            app.UseAuthorization();
            //AntiforgeryCookies
            app.AddAntiforgery(antiforgery);

            app.UseEndpoints(endpoints =>
            {
                ConfigRouting.ConfigureRoutes(endpoints);
            });
        }