Startup.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.AspNetCore.Builder;
  4. using Microsoft.AspNetCore.Hosting;
  5. using Microsoft.AspNetCore.Http;
  6. using Microsoft.AspNetCore.Http.Features;
  7. using Microsoft.AspNetCore.StaticFiles;
  8. using Microsoft.Extensions.Configuration;
  9. using Microsoft.Extensions.DependencyInjection;
  10. using Microsoft.Extensions.Hosting;
  11. namespace MySystem
  12. {
  13. public class Startup
  14. {
  15. public Startup(IConfiguration configuration)
  16. {
  17. Configuration = configuration;
  18. }
  19. public IConfiguration Configuration { get; }
  20. // This method gets called by the runtime. Use this method to add services to the container.
  21. public void ConfigureServices(IServiceCollection services)
  22. {
  23. services.AddControllersWithViews();
  24. services.AddRouting(options =>
  25. {
  26. options.LowercaseUrls = true;
  27. });
  28. services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
  29. // services.AddCors(option => option.AddPolicy("cors", policy => policy.AllowAnyHeader().AllowAnyMethod().AllowCredentials().SetIsOriginAllowed(_ => true)));
  30. services.AddMvc(options =>
  31. {
  32. options.EnableEndpointRouting = false;
  33. options.Filters.Add(typeof(GlobalExceptions));
  34. });
  35. services.AddSession(options =>
  36. {
  37. // 设置 Session 过期时间
  38. options.IdleTimeout = TimeSpan.FromHours(1);
  39. options.Cookie.HttpOnly = true;
  40. });
  41. services.Configure<FormOptions>(x =>
  42. {
  43. x.MultipartBodyLengthLimit = 50 * 1024 * 1024;//不到300M
  44. });
  45. string appkey = Configuration["Setting:AppKey"];
  46. string appid = Configuration["Setting:AppId"];
  47. string checkurl = Configuration["Setting:CheckUrl"];
  48. string serviceurl = Configuration["Setting:WebServiceUrl"];
  49. string schemeurl = Configuration["Setting:DbSchemeUrl"];
  50. MySystemLib.SystemPublicFuction.appkey = appkey;
  51. MySystemLib.SystemPublicFuction.appid = appid;
  52. MySystemLib.SystemPublicFuction.checkurl = checkurl;
  53. MySystemLib.SystemPublicFuction.appcheck = "success";
  54. RedisDbconn.csredis = new CSRedis.CSRedisClient(Configuration["Setting:RedisConnStr"]);
  55. }
  56. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  57. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  58. {
  59. if (env.IsDevelopment())
  60. {
  61. app.UseDeveloperExceptionPage();
  62. Library.ConfigurationManager.EnvironmentFlag = 1;
  63. }
  64. else
  65. {
  66. app.UseExceptionHandler("/Home/Error");
  67. app.UseHsts();
  68. Library.ConfigurationManager.EnvironmentFlag = 2;
  69. }
  70. Library.function.WritePage("/", "WebRootPath.txt", env.WebRootPath);
  71. app.UseStaticFiles();
  72. app.UseStaticFiles(new StaticFileOptions
  73. {
  74. ContentTypeProvider = new FileExtensionContentTypeProvider(new Dictionary<string, string>
  75. {
  76. { ".apk", "application/vnd.android.package-archive" }
  77. })
  78. });
  79. app.UseCors("cors");
  80. app.UseAuthentication();
  81. app.UseRouting();
  82. app.UseAuthorization();
  83. app.UseSession();
  84. app.UseEndpoints(endpoints =>
  85. {
  86. endpoints.MapControllerRoute(
  87. name: "default",
  88. pattern: "{controller=Home}/{action=Index}/{Id?}");
  89. });
  90. //必须打开的
  91. StatService.Instance.GetApMysqlData();
  92. // TableSplitService.Instance.Start();
  93. // TableSplitService.Instance.AddBefore();
  94. //必须打开的
  95. }
  96. }
  97. }