Startup.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using DllEapBll;
  5. using log4net.AspNetCore;
  6. using Microsoft.AspNetCore.Builder;
  7. using Microsoft.AspNetCore.Hosting;
  8. using Microsoft.AspNetCore.Http;
  9. using Microsoft.AspNetCore.HttpsPolicy;
  10. using Microsoft.AspNetCore.Mvc;
  11. using Microsoft.Extensions.Configuration;
  12. using Microsoft.Extensions.DependencyInjection;
  13. using Microsoft.Extensions.Logging;
  14. using WebAppletStatus.Config;
  15. namespace WebAppletStatus
  16. {
  17. public class Startup
  18. {
  19. public Startup(IConfiguration configuration)
  20. {
  21. Configuration = configuration;
  22. }
  23. public IConfiguration Configuration { get; }
  24. // This method gets called by the runtime. Use this method to add services to the container.
  25. public void ConfigureServices(IServiceCollection services)
  26. {
  27. services.Configure<CookiePolicyOptions>(options =>
  28. {
  29. // This lambda determines whether user consent for non-essential cookies is needed for a given request.
  30. options.CheckConsentNeeded = context => true;
  31. options.MinimumSameSitePolicy = SameSiteMode.None;
  32. });
  33. services.AddSingleton<AppletStatusCollection>();
  34. services.AddSingleton<AppletStatusCollectionBll>();
  35. services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
  36. }
  37. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  38. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory factory)
  39. {
  40. ILogger myloger = factory.AddLog4Net().CreateLogger(typeof(Startup));
  41. if (env.IsDevelopment())
  42. {
  43. app.UseDeveloperExceptionPage();
  44. }
  45. else
  46. {
  47. app.UseExceptionHandler("/Error");
  48. }
  49. string errorinfo = "";
  50. var collectionManager = app.ApplicationServices.GetService(typeof(AppletStatusCollectionBll)) as AppletStatusCollectionBll;
  51. collectionManager.DoCollection(ref errorinfo);
  52. if (errorinfo != "")
  53. {
  54. myloger.LogError($"启动服务发生错误:{errorinfo}");
  55. }
  56. else
  57. {
  58. myloger.LogError("启动服务成功。");
  59. }
  60. app.UseStaticFiles();
  61. app.UseCookiePolicy();
  62. app.UseCors(builder => builder
  63. .AllowAnyOrigin()
  64. .AllowAnyMethod()
  65. .AllowAnyHeader()
  66. .AllowCredentials());
  67. app.UseMvc(routes =>
  68. {
  69. routes.MapRoute(
  70. name: "default",
  71. template: "{controller=Home}/{action=Index}/{id?}");
  72. });
  73. //app.UseStaticFiles();
  74. //app.UseCookiePolicy();
  75. //app.UseMvc();
  76. }
  77. }
  78. }