Example #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,
                              IHostApplicationLifetime appLifetime, IOptions <Dictionary <string, string> > options,
                              IOptions <SenparcSetting> senparcSetting, IOptions <SenparcWeixinSetting> senparcWeixinSetting)
        {
            //if (env.IsDevelopment())
            //{
            //    app.UseDeveloperExceptionPage();
            // //  app.AddRazorRuntimeCompilation();
            //}
            //else
            //{
            //    app.UseExceptionHandler("/Home/Error");
            //    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
            //    app.UseHsts();
            //}
            app.UseCookiePolicy();
            app.UseHttpsRedirection();

            //添加新的媒体文件类型,静态文件路由
            app.UseAtlassDefaultFiles(options);

            app.UseRouting();
            #region 自定义中间件
            app.UseMiddleware <AtlassHttpRequestMiddleware>();
            //app.UseMiddleware(typeof(AtlassExceptionMiddlerware));
            #endregion
            app.UseAuthorization();
            app.UseSession();

            app.UseEasyCachingResponseCaching();


            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapControllerRoute(name: "areaRoute",
                                             pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
            });

            //启动hangfire服务和面板
            app.UseHangfireServer(new BackgroundJobServerOptions
            {
                Queues = new[] { "default" }
            });
            app.UseHangfireDashboard();
            //app.UseHangfireDashboard("/hangfire", new DashboardOptions()
            //{
            //    Authorization = new[] { new HangfireAuthorizeFilter() }
            //});


            //关于 UseSenparcGlobal() 的更多用法见 CO2NET Demo:
            //https://github.com/Senparc/Senparc.CO2NET/blob/master/Sample/Senparc.CO2NET.Sample.netcore/Startup.cs
            IRegisterService register = RegisterService.Start(senparcSetting.Value)
                                        .UseSenparcGlobal();

            register.ChangeDefaultCacheNamespace("DefaultCO2NETCache");
            register.UseSenparcWeixin(senparcWeixinSetting.Value, senparcSetting.Value)

            #region 注册公众号(按需)
            //注册公众号(可注册多个)                                                -- DPBMARK MP
            .RegisterMpAccount(senparcWeixinSetting.Value, "doctor_platform_mp")     // DPBMARK_END //注册最新微信支付版本(V3)(可注册多个)
            .RegisterTenpayV3(senparcWeixinSetting.Value, "doctor_platform_tenpay"); //记录到同一个 SenparcWeixinSettingItem 对象中
            #endregion

            //应用程序启动后
            appLifetime.ApplicationStarted.Register(() => {
                try
                {
                    GlobalParamsDto.WebRoot = env.WebRootPath;
                    //SugarDbConn.DbConnectStr = this.Configuration.GetSection("DbConn:mysqlConn").Value;   //为数据库连接字符串赋值
                    GlobalParamsDto.Host = this.Configuration.GetSection("WebHost:Host").Value;

                    //初始化栏目相关的缓存
                    CmsCacheInit.Init();
                }
                catch (Exception e)
                {
                    LogNHelper.Exception(e);
                }
            });
        }
Example #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env,
                              IHostApplicationLifetime appLifetime, IOptions <Dictionary <string, string> > options,
                              IOptions <SenparcSetting> senparcSetting, IOptions <SenparcWeixinSetting> senparcWeixinSetting)
        {
            GlobalContext.HostingEnvironment = env;
            //GlobalContext.AutofacContainer = app.ApplicationServices.GetAutofacRoot();
            AutofacUtil.Container = app.ApplicationServices.GetAutofacRoot();

            //异常处理
            // app.UseExceptionHandler("/Home/Error");
            app.UseStatusCodePagesWithRedirects("/Login/Error/{0}");

            //cookie策略
            app.UseCookiePolicy();
            app.UseHttpsRedirection();

            //添加新的媒体文件类型,静态文件路由

            app.UseAtlassDefaultFiles(options);

            app.UseRouting();
            #region 自定义中间件
            app.UseMiddleware <AtlassHttpRequestMiddleware>();
            //app.UseMiddleware(typeof(AtlassExceptionMiddlerware));
            #endregion
            app.UseAuthorization();
            app.UseSession();

            app.UseEasyCachingResponseCaching();


            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapControllerRoute(name: "areaRoute",
                                             pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
            });

            //启动hangfire服务和面板
            if (GlobalContext.CrontabConfigDto.Enable)
            {
                app.UseHangfireServer(new BackgroundJobServerOptions
                {
                    Queues = new[] { "default" }
                });
                //  app.UseHangfireDashboard();
                app.UseHangfireDashboard("/easytask", new DashboardOptions()
                {
                    Authorization = new[] { new HangfireAuthorizeFilter() }
                });
            }



            //关于 UseSenparcGlobal() 的更多用法见 CO2NET Demo:
            //https://github.com/Senparc/Senparc.CO2NET/blob/master/Sample/Senparc.CO2NET.Sample.netcore/Startup.cs
            IRegisterService register = RegisterService.Start(senparcSetting.Value)
                                        .UseSenparcGlobal();

            register.ChangeDefaultCacheNamespace("DefaultCO2NETCache");
            register.UseSenparcWeixin(senparcWeixinSetting.Value, senparcSetting.Value)

            #region 注册公众号(按需)
            //注册公众号(可注册多个)                                                -- DPBMARK MP
            .RegisterMpAccount(senparcWeixinSetting.Value, "doctor_platform_mp")     // DPBMARK_END //注册最新微信支付版本(V3)(可注册多个)
            .RegisterTenpayV3(senparcWeixinSetting.Value, "doctor_platform_tenpay"); //记录到同一个 SenparcWeixinSettingItem 对象中
            #endregion

            //应用程序启动后
            appLifetime.ApplicationStarted.Register(() => {
                try
                {
                    GlobalParamsDto.WebRoot = env.WebRootPath;

                    //初始化栏目相关的缓存
                    CmsCacheInit.Init();
                }
                catch (Exception e)
                {
                    LoggerHelper.Exception(e);
                }
            });
        }