Startup.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  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. using Microsoft.Extensions.Hosting;
  9. namespace aspnetapp
  10. {
  11. public class Startup
  12. {
  13. public Startup(IConfiguration configuration)
  14. {
  15. Configuration = configuration;
  16. }
  17. public IConfiguration Configuration { get; }
  18. // This method gets called by the runtime. Use this method to add services to the container.
  19. public void ConfigureServices(IServiceCollection services)
  20. {
  21. services.Configure<CookiePolicyOptions>(options =>
  22. {
  23. // This lambda determines whether user consent for non-essential cookies is needed for a given request.
  24. options.CheckConsentNeeded = context => true;
  25. options.MinimumSameSitePolicy = SameSiteMode.None;
  26. });
  27. services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
  28. services.AddControllers();
  29. }
  30. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  31. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  32. {
  33. if (env.IsDevelopment())
  34. {
  35. app.UseDeveloperExceptionPage();
  36. }
  37. else
  38. {
  39. app.UseExceptionHandler("/Home/Error");
  40. app.UseHsts();
  41. }
  42. app.UseStaticFiles();
  43. app.UseCookiePolicy();
  44. app.UseRouting();
  45. app.UseEndpoints(e => e.MapControllerRoute(
  46. name: "default",
  47. pattern: "{controller=Home}/{action=Index}/{id?}"));
  48. }
  49. }
  50. }