Startup.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using Microsoft.AspNetCore.Builder;
  3. using Microsoft.AspNetCore.Hosting;
  4. using Microsoft.Extensions.Configuration;
  5. using Microsoft.Extensions.DependencyInjection;
  6. using Microsoft.Extensions.Hosting;
  7. namespace jsonapi
  8. {
  9. public class Startup
  10. {
  11. public Startup(IConfiguration configuration)
  12. {
  13. Startup.Configuration = configuration;
  14. }
  15. public static IConfiguration Configuration { get; set; }
  16. // This method gets called by the runtime. Use this method to add services to the container.
  17. public void ConfigureServices(IServiceCollection services)
  18. {
  19. services.AddControllers();
  20. services.AddMvc().AddNewtonsoftJson();
  21. }
  22. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  23. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  24. {
  25. if (env.IsDevelopment())
  26. {
  27. app.UseDeveloperExceptionPage();
  28. }
  29. if(Configuration.GetValue<Boolean>("UseHttps")) {
  30. app.UseHttpsRedirection();
  31. }
  32. app.UseRouting();
  33. app.UseAuthorization();
  34. app.UseEndpoints(endpoints =>
  35. {
  36. endpoints.MapControllers();
  37. });
  38. }
  39. }
  40. }