Startup.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. MySystemLib.SystemPublicFuction.appcheck = "success";
  46. RedisDbconn.csredis = new CSRedis.CSRedisClient(Configuration["Setting:RedisConnStr"]);
  47. }
  48. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  49. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  50. {
  51. if (env.IsDevelopment())
  52. {
  53. app.UseDeveloperExceptionPage();
  54. // app.UseExceptionHandler("/Home/Error");
  55. }
  56. else
  57. {
  58. app.UseExceptionHandler("/Home/Error");
  59. app.UseHsts();
  60. }
  61. Library.ConfigurationManager.EnvironmentFlag = 2;
  62. Library.function.WritePage("/", "WebRootPath.txt", env.WebRootPath);
  63. app.UseStaticFiles();
  64. app.UseCors("cors");
  65. app.UseAuthentication();
  66. app.UseRouting();
  67. app.UseAuthorization();
  68. app.UseSession();
  69. app.UseEndpoints(endpoints =>
  70. {
  71. endpoints.MapControllerRoute(
  72. name: "default",
  73. pattern: "{controller=Home}/{action=Index}/{Id?}");
  74. });
  75. //必须打开的
  76. ExportService.Instance.Start();
  77. //必须打开的
  78. }
  79. }
  80. }