Пример #1
0
 public static void Startup()
 {
     //移除aspx视图引擎
     ViewEngines.Engines.RemoveAt(0);
     // AutoMapper映射注册
     AutoMapperConfig.Register();
     // Autofac 依赖注入
     AutofacConfig.Register();
     // Hangfire 系统任务配置
     HangfireConfig.Register();
     System.Web.Http.GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
 }
Пример #2
0
        /// <summary>
        ///  This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        /// </summary>
        /// <param name="app"></param>
        /// <param name="env"></param>
        /// <param name="setting"></param>
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, Iyoshop_settingService setting)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error/Index");
                // 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.UseException();
            }
            app.UseResponseCompression();
            // URL重写
            app.UseRewriter(new RewriteOptions().AddRedirectToNonWww());
            //注入静态HttpContext对象
            app.UseStaticHttpContext();
            //注入Session
            app.UseSession();
            //app.UseHttpsRedirection();
            app.UseStaticFiles(new StaticFileOptions //静态资源缓存策略
            {
                OnPrepareResponse = ctx =>
                {
                    ctx.Context.Response.Headers[HeaderNames.CacheControl] = "public,no-cache";
                    ctx.Context.Response.Headers[HeaderNames.Expires]      = DateTime.UtcNow.AddDays(7).ToString("R");
                },
                ContentTypeProvider = new FileExtensionContentTypeProvider(MimeMapper.MimeTypes)
            }).UseCookiePolicy();
            //启用网站防火墙
            app.UseRequestIntercept();
            //自定义Debug模式下的操作
            if (AppConfig.IsDebug)
            {
                CommonHelper.SystemSettings = setting.LoadEntities(l => l.wxapp_id == 10001).ToList().ToDictionary(s => s.key, s => JObject.Parse(s.values));
            }
            //配置hangfire
            app.UseHangfireServer().UseHangfireDashboard("/taskcenter", new DashboardOptions()
            {
                Authorization = new[]
                {
                    new MyRestrictiveAuthorizationFilter()
                }
            });
            //配置跨域
            app.UseCors(builder =>
            {
                builder.AllowAnyHeader();
                builder.AllowAnyMethod();
                builder.AllowAnyOrigin();
                builder.AllowCredentials();
            });
            //启动Response缓存
            app.UseResponseCaching();
            //配置swagger
            app.UseSwagger().UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", CommonHelper.SystemSettings["store"]["name"].Value <string>());
                c.RoutePrefix = "swagger";
            });
            //配置SignalR
            app.UseSignalR(hub => hub.MapHub <MyHub>("/hubs"));
            //初始化定时任务
            HangfireConfig.Start();
            //配置默认路由
            app.UseMvcWithDefaultRoute();
        }