Startup.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using Cksoft.Unity;
  2. using Microsoft.AspNetCore.Builder;
  3. using Microsoft.AspNetCore.Hosting;
  4. using Microsoft.AspNetCore.Http;
  5. using Microsoft.AspNetCore.Mvc;
  6. using Microsoft.Extensions.Configuration;
  7. using Microsoft.Extensions.DependencyInjection;
  8. namespace WebLogViewer
  9. {
  10. public class Startup
  11. {
  12. public Startup(IConfiguration configuration)
  13. {
  14. Configuration = configuration;
  15. }
  16. public IConfiguration Configuration { get; }
  17. // This method gets called by the runtime. Use this method to add services to the container.
  18. public void ConfigureServices(IServiceCollection services)
  19. {
  20. services.Configure<CookiePolicyOptions>(options =>
  21. {
  22. // This lambda determines whether user consent for non-essential cookies is needed for a given request.
  23. options.CheckConsentNeeded = context => true;
  24. options.MinimumSameSitePolicy = SameSiteMode.None;
  25. });
  26. services.AddCors(options =>
  27. {
  28. options.AddPolicy("all", builder =>
  29. {
  30. builder.AllowAnyOrigin() //允许任何来源的主机访问
  31. .AllowAnyMethod()
  32. .AllowAnyHeader()
  33. .AllowCredentials();//指定处理cookie
  34. });
  35. });
  36. services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
  37. }
  38. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  39. public void Configure(IApplicationBuilder app, IHostingEnvironment env)
  40. {
  41. if (env.IsDevelopment())
  42. {
  43. app.UseDeveloperExceptionPage();
  44. }
  45. else
  46. {
  47. app.UseExceptionHandler("/Error");
  48. }
  49. AppConfigurtaionServices.Configuration = Configuration;
  50. app.UseCors("all");
  51. app.UseStaticFiles();
  52. app.UseCookiePolicy();
  53. app.UseMvc();
  54. }
  55. }
  56. }