示例#1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UserSwaggerConfig();

            AppHttpContext.Configure(app.ApplicationServices.
                                     GetRequiredService <Microsoft.AspNetCore.Http.IHttpContextAccessor>());

            app.UseHttpCacheHeaders();

            app.UseSession();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
示例#2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env,
                              ILoggerFactory loggerFactory, AmstramgramContext db)
        {
            var forwardedHeadersOptions = new ForwardedHeadersOptions
            {
                ForwardedHeaders      = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto,
                RequireHeaderSymmetry = false
            };

            forwardedHeadersOptions.KnownNetworks.Clear();
            forwardedHeadersOptions.KnownProxies.Clear();

            app.UseForwardedHeaders(forwardedHeadersOptions);

            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            app.UseCors(builder => builder
                        .AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader()
                        .AllowCredentials());

            app.UseSession();

            app.Use((httpContext, nextMiddleware) =>
            {
                httpContext.Session.SetObject("_SessionKey", String.Empty);
                httpContext.Session.SetObject("_SessionDate", DateTime.Now);

                return(nextMiddleware());
            });

            app.UseStaticFiles();

            app.UseMvc();

            app.UseCookiePolicy();

            /*var optionsRewrite = new RewriteOptions()
             *                .AddRedirectToHttps(StatusCodes.Status301MovedPermanently, 63423);*/

            //app.UseRewriter(optionsRewrite);
            AppHttpContext.Configure(app.ApplicationServices.GetRequiredService <IHttpContextAccessor>());
            // db.EnsureSeedData();
        }
 public static IApplicationBuilder UseHttpContext(this IApplicationBuilder app)
 {
     AppHttpContext.Configure(app.ApplicationServices.GetRequiredService <IHttpContextAccessor>());
     return(app);
 }