Startup.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using DllLogServer;
  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. namespace WebMainHsms
  15. {
  16. public class Startup
  17. {
  18. public Startup(IConfiguration configuration)
  19. {
  20. Configuration = configuration;
  21. }
  22. public IConfiguration Configuration { get; }
  23. // This method gets called by the runtime. Use this method to add services to the container.
  24. public void ConfigureServices(IServiceCollection services)
  25. {
  26. services.Configure<CookiePolicyOptions>(options =>
  27. {
  28. // This lambda determines whether user consent for non-essential cookies is needed for a given request.
  29. options.CheckConsentNeeded = context => true;
  30. options.MinimumSameSitePolicy = SameSiteMode.None;
  31. });
  32. services.AddSingleton<ILogServer, LogServer>();
  33. services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
  34. }
  35. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  36. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory factory)
  37. {
  38. ILogger myloger = factory.AddLog4Net().CreateLogger(typeof(Startup));// app.ApplicationServices.GetRequiredService<ILogger<Startup>>();
  39. if (env.IsDevelopment())
  40. {
  41. app.UseDeveloperExceptionPage();
  42. }
  43. else
  44. {
  45. app.UseExceptionHandler("/Home/Error");
  46. app.UseHsts();
  47. }
  48. //获取通讯管理主程序实例
  49. var server = app.ApplicationServices.GetRequiredService<ILogServer>();
  50. string errorinfo = "";
  51. server.Start(ref errorinfo);
  52. myloger.LogError(errorinfo);
  53. app.UseHttpsRedirection();
  54. app.UseStaticFiles();
  55. app.UseCookiePolicy();
  56. app.UseCors(builder => builder
  57. .AllowAnyOrigin()
  58. .AllowAnyMethod()
  59. .AllowAnyHeader()
  60. .AllowCredentials());
  61. app.UseMvc(routes =>
  62. {
  63. routes.MapRoute(
  64. name: "default",
  65. template: "{controller=Home}/{action=Index}/{id?}");
  66. });
  67. }
  68. }
  69. }