Startup.cs 1.5 KB

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