コード例 #1
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, IServiceProvider service, IApplicationLifetime appLifetime)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();
            //SusHttpContext.Config(app.ApplicationServices.GetRequiredService<IHttpContextAccessor>());
            //处理静态注入类ServiceProvider的中间件,感觉不是很优雅,等以后大神的解决方案吧
            app.UseMiddleware <StaticResolverMiddleware>();
            StaticResolver.Config(app.ApplicationServices);
            EngineContext.RunStartUpTask(service);
            app.UseApplicationInsightsRequestTelemetry();
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationScheme  = "Cookie",
                LoginPath             = new PathString("/Login"),
                AccessDeniedPath      = new PathString("/Forbidden"),
                AutomaticAuthenticate = true,
                AutomaticChallenge    = true
            });
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseApplicationInsightsExceptionTelemetry();
            app.UseStaticFiles();
            //app.Use(new Func<RequestDelegate, RequestDelegate>(nextapp => new ContainerMiddleware(nextapp,app.ApplicationServices)))
            app.UseMvc(routes =>
            {
                var rp = service.GetService <IRoutePublisher>();
                rp.RegisterRoutes(routes);
                routes.MapGet("{blog}/{controller}/{action}/id?", context => {
                });
                routes.MapRoute(
                    name: "default",
                    template: "{Host=Admin}/{controller=Home}/{action=Index}/{id?}");
            });
            //appLifetime.ApplicationStopped.Register(() => this.ApplicationContainer.Dispose());
        }