平安校园
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 3 месеца
преди 4 месеца
преди 3 месеца
преди 4 месеца
преди 4 месеца
преди 4 месеца
преди 3 месеца
преди 4 месеца
преди 3 месеца
преди 4 месеца
преди 3 месеца
преди 3 месеца
преди 2 месеца
преди 4 месеца
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using MoYu.DependencyInjection;
  2. using SafeCampus.Application.Manager.DeepelephManager;
  3. namespace SafeCampus.Web.Core;
  4. /// <summary>
  5. /// Web启动项配置
  6. /// </summary>
  7. [AppStartup(99)]
  8. public class Startup : AppStartup
  9. {
  10. public void ConfigureServices(IServiceCollection services)
  11. {
  12. //启动LoggingMonitor操作日志写入数据库组件
  13. services.AddComponent<LoggingMonitorComponent>();
  14. //认证组件
  15. services.AddComponent<AuthComponent>();
  16. //启动Web设置ConfigureServices组件
  17. services.AddComponent<WebSettingsComponent>();
  18. //gip压缩
  19. services.AddComponent<GzipCompressionComponent>();
  20. //定时任务
  21. //services.AddSchedule();
  22. //添加控制器相关
  23. services.AddControllers().AddNewtonsoftJson(options => //配置json
  24. {
  25. options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();// 首字母小写(驼峰样式)
  26. options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";// 时间格式化
  27. options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;// 忽略循环引用
  28. }).AddInjectWithUnifyResult<SafeCampusResultProvider>()//配置统一返回模型
  29. ;
  30. //Nginx代理的话获取真实IP
  31. services.Configure<ForwardedHeadersOptions>(options =>
  32. {
  33. options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
  34. //新增如下两行
  35. options.KnownNetworks.Clear();
  36. options.KnownProxies.Clear();
  37. });
  38. services.AddRemoteRequest();
  39. services.AddSignalR();
  40. }
  41. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  42. {
  43. //var isDevelopment = App.HostEnvironment.IsDevelopment();
  44. //var isProduction = App.HostEnvironment.IsProduction();
  45. if (env.IsProduction())
  46. {
  47. //启动执行消息订阅
  48. Scoped.Create((_, scope) =>
  49. {
  50. var deepeleph = scope.ServiceProvider.GetRequiredService<IDeepelephManager>();
  51. deepeleph.SubscribeAlarm();
  52. //deepeleph.SubscribersRoomCall();
  53. deepeleph.SubscriberAttendance();
  54. });
  55. }
  56. //启动Web设置Configure组件
  57. app.UseComponent<WebSettingsApplicationComponent>(env);
  58. if (env.IsDevelopment())
  59. {
  60. app.UseDeveloperExceptionPage();
  61. }
  62. else
  63. {
  64. //启用gzip压缩
  65. app.UseResponseCompression();
  66. }
  67. // 启用HTTPS
  68. app.UseHttpsRedirection();
  69. // 添加状态码拦截中间件
  70. app.UseUnifyResultStatusCodes();
  71. app.UseStaticFiles();//静态文件访问配置
  72. //静态文件访问配置,暂时不开启
  73. // app.UseStaticFiles(new StaticFileOptions
  74. // {
  75. // ServeUnknownFileTypes = true,
  76. // FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot")),//wwwroot相当于真实目录
  77. // OnPrepareResponse = c =>
  78. // {
  79. // c.Context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
  80. // c.Context.Response.Headers.Append("Cache-Control", "public, max-age=604800");
  81. // },
  82. // RequestPath = new PathString("/files")//src相当于别名,为了安全
  83. // });
  84. app.UseRouting();//路由配置
  85. app.UseCorsAccessor();//跨域配置
  86. app.UseWebStatus();//网站开启状态
  87. app.UseAuthentication();//认证
  88. app.UseAuthorization();//授权
  89. app.UseInject(string.Empty);
  90. app.UseForwardedHeaders();//Nginx代理的话获取真实IP
  91. app.UseEndpoints(endpoints =>
  92. {
  93. // 注册集线器
  94. endpoints.MapHubs();
  95. endpoints.MapControllers();
  96. });
  97. var path = Path.Combine(Directory.GetCurrentDirectory(), "Files");
  98. if (!Directory.Exists(path))
  99. {
  100. Directory.CreateDirectory(path);
  101. }
  102. var alarmImg = Path.Combine(Directory.GetCurrentDirectory(), "Files","alarmImg");
  103. if (!Directory.Exists(alarmImg))
  104. {
  105. Directory.CreateDirectory(alarmImg);
  106. }
  107. var personImg = Path.Combine(Directory.GetCurrentDirectory(), "Files", "personImg");
  108. if (!Directory.Exists(personImg))
  109. {
  110. Directory.CreateDirectory(personImg);
  111. }
  112. var roomCallImg = Path.Combine(Directory.GetCurrentDirectory(), "Files", "roomCallImg");
  113. if (!Directory.Exists(roomCallImg))
  114. {
  115. Directory.CreateDirectory(roomCallImg);
  116. }
  117. var attendanceImg = Path.Combine(Directory.GetCurrentDirectory(), "Files", "attendanceImg");
  118. if (!Directory.Exists(attendanceImg))
  119. {
  120. Directory.CreateDirectory(attendanceImg);
  121. }
  122. var cameraImg = Path.Combine(Directory.GetCurrentDirectory(), "Files", "cameraImg");
  123. if (!Directory.Exists(cameraImg))
  124. {
  125. Directory.CreateDirectory(cameraImg);
  126. }
  127. app.UseFileServer(new FileServerOptions()
  128. {
  129. FileProvider = new PhysicalFileProvider(path),
  130. RequestPath = new PathString("/Files"),
  131. EnableDirectoryBrowsing = true
  132. });
  133. }
  134. }