Esempio n. 1
0
        public static void ConfigureSite(this IApplicationBuilder app, IServiceProvider serviceProvider, IWebHostEnvironment env, IHostApplicationLifetime lifetime)
        {
            app.UseStaticHostEnviroment();
            APPCommon.WebHostEnvironment = env;
            lifetime.ApplicationStarted.Register(OnStart);      //1:应用启动时加载配置,2:应用启动后注册服务中心
            lifetime.ApplicationStopped.Register(UnRegService); //应用停止后从服务中心注销
            //app.UseSimpleInjector(APPCommon.Resover.Container);
            app.UseDeveloperExceptionPage();
            var appConfig = APPCommon.AppConfig;
            var UserDefaultStaticalDir = appConfig.GetDicstring("UserDefaultStaticalDir");
            var webroot = Path.Combine(Directory.GetCurrentDirectory(), UserDefaultStaticalDir);

            if (!Directory.Exists(webroot))
            {
                Directory.CreateDirectory(webroot);
            }


            CreatUserSpaceDirectory(app);
            APP.ConfigureSiteAllModules(app);
            APPCommon.ConfigureSite(app, env);
            app.UseStaticFiles();

            //app.UseCookiePolicy(); //是否启用cookie隐私

            var isEnableSwagger = Convert.ToBoolean(appConfig.GetDicstring("isEnableSwagger"));;

            if (isEnableSwagger)
            {
                //启用中间件服务生成Swagger作为JSON终结点
                app.UseSwagger();
                //启用中间件服务对swagger-ui,指定Swagger JSON终结点
                app.UseSwaggerUI(c =>
                {
                    c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
                });
            }
            app.UsePhp(new PhpRequestOptions()
            {
                RootPath = APPCommon.UserUploadBaseDir, ScriptAssembliesName = new string[] { "UniOrm.PHP" }
            });
            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();
            var isAllowCros = Convert.ToBoolean(appConfig.GetDicstring("isAllowCros"));

            if (isAllowCros)
            {
                app.UseCors("allow_all");
            }
            var AreaName = appConfig.GetDicstring("AreaName");

            //url 重写。。。
            // var rewrite = new RewriteOptions()
            //.AddRewrite("first", "home/index", 301);
            // app.UseRewriter(rewrite);

            //用户session服务
            app.UseSession();
            //using (var scope = serviceProvider.CreateScope())
            //{
            //    var _actionProvider = scope.ServiceProvider
            //        .GetService<DynamicActionProvider>();
            //    var _dynamicChangeTokenProvider = scope.ServiceProvider
            //        .GetService<DynamicChangeTokenProvider>();
            // WebSetup.BuildAllDynamicActions(_actionProvider, _dynamicChangeTokenProvider).GetAwaiter().GetResult();
            //}

            app.UseTheme();//启用theme中间件
            app.UseEndpoints(endpoints =>
            {
                //endpoints.MapControllerRoute(
                //    name: "default",
                //    pattern: "{controller=Home}/{action=Index}/{id?}");

                endpoints.MapAreaControllerRoute(name: "areas", "areas", pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
                //routes.MapRoute("areaRoute", "{"+ AreaName + ":exists}/{controller}/{action=Index}/{id?}");
                endpoints.MapControllerRoute(
                    "factory", "/fact/{action}", new { controller = "Fact", action = "Index" });
                endpoints.MapControllerRoute(
                    "cmsinstall", "/CmsInstall/{action}", new { controller = "CmsInstall", action = "Index" });
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapControllerRoute(
                    "all", @"{**path}", new { controller = "FactoryBuilder", action = "Index" });

                endpoints.MapRazorPages();
            });

            // APPCommon.Resover.Container.Verify();
            // BuildAllDynamicActions();
        }