123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- using System;
- using System.Collections.Generic;
- using Microsoft.AspNetCore.Builder;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Http.Features;
- using Microsoft.AspNetCore.StaticFiles;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.Extensions.Hosting;
- namespace MySystem
- {
- public class Startup
- {
- public Startup(IConfiguration configuration)
- {
- Configuration = configuration;
- }
- public IConfiguration Configuration { get; }
- // This method gets called by the runtime. Use this method to add services to the container.
- public void ConfigureServices(IServiceCollection services)
- {
- services.AddControllersWithViews();
- services.AddRouting(options =>
- {
- options.LowercaseUrls = true;
- });
- services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
- // services.AddCors(option => option.AddPolicy("cors", policy => policy.AllowAnyHeader().AllowAnyMethod().AllowCredentials().SetIsOriginAllowed(_ => true)));
- services.AddMvc(options =>
- {
- options.EnableEndpointRouting = false;
- options.Filters.Add(typeof(GlobalExceptions));
- });
- services.AddSession(options =>
- {
- // 设置 Session 过期时间
- options.IdleTimeout = TimeSpan.FromHours(1);
- options.Cookie.HttpOnly = true;
- });
- services.Configure<FormOptions>(x =>
- {
- x.MultipartBodyLengthLimit = 50 * 1024 * 1024;//不到300M
- });
- string appkey = Configuration["Setting:AppKey"];
- string appid = Configuration["Setting:AppId"];
- string checkurl = Configuration["Setting:CheckUrl"];
- string serviceurl = Configuration["Setting:WebServiceUrl"];
- string schemeurl = Configuration["Setting:DbSchemeUrl"];
- MySystemLib.SystemPublicFuction.appkey = appkey;
- MySystemLib.SystemPublicFuction.appid = appid;
- MySystemLib.SystemPublicFuction.checkurl = checkurl;
- MySystemLib.SystemPublicFuction.appcheck = "success";
-
- RedisDbconn.csredis = new CSRedis.CSRedisClient(Configuration["Setting:RedisConnStr"]);
- }
- // 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();
- Library.ConfigurationManager.EnvironmentFlag = 1;
- }
- else
- {
- app.UseExceptionHandler("/Home/Error");
- app.UseHsts();
- Library.ConfigurationManager.EnvironmentFlag = 2;
- }
- Library.function.WritePage("/", "WebRootPath.txt", env.WebRootPath);
- app.UseStaticFiles();
- app.UseStaticFiles(new StaticFileOptions
- {
- ContentTypeProvider = new FileExtensionContentTypeProvider(new Dictionary<string, string>
- {
- { ".apk", "application/vnd.android.package-archive" }
- })
- });
- app.UseCors("cors");
- app.UseAuthentication();
- app.UseRouting();
- app.UseAuthorization();
- app.UseSession();
- app.UseEndpoints(endpoints =>
- {
- endpoints.MapControllerRoute(
- name: "default",
- pattern: "{controller=Home}/{action=Index}/{Id?}");
- });
-
- //必须打开的
- StatService.Instance.Start();
- TableSplitService.Instance.Start();
- // TableSplitService.Instance.AddBefore();
- //必须打开的
- }
- }
- }
|