Startup.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using Newtonsoft.Json;
  2. using Microsoft.Extensions.DependencyInjection;
  3. namespace EVCB_OCPP.DBAPI;
  4. public class Startup
  5. {
  6. public Startup(IConfiguration configuration)
  7. {
  8. Configuration = configuration;
  9. }
  10. public IConfiguration Configuration { get; }
  11. public void ConfigureServices(IServiceCollection services)
  12. {
  13. JsonConvert.DefaultSettings = () => new JsonSerializerSettings()
  14. {
  15. NullValueHandling = NullValueHandling.Ignore,
  16. DateFormatString = "yyyy-MM-dd'T'HH':'mm':'ss'Z'"
  17. };
  18. services.AddControllersWithViews()
  19. .AddControllersAsServices()
  20. // Newtonsoft.Json is added for compatibility reasons
  21. // The recommended approach is to use System.Text.Json for serialization
  22. // Visit the following link for more guidance about moving away from Newtonsoft.Json to System.Text.Json
  23. // https://docs.microsoft.com/dotnet/standard/serialization/system-text-json-migrate-from-newtonsoft-how-to
  24. .AddNewtonsoftJson(options =>
  25. {
  26. options.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
  27. options.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.None;
  28. options.SerializerSettings.DateFormatString = "yyyy/MM/dd'T'HH':'mm':'ss'Z'";
  29. options.UseMemberCasing();
  30. });
  31. }
  32. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  33. {
  34. if (env.IsDevelopment())
  35. {
  36. app.UseDeveloperExceptionPage();
  37. }
  38. else
  39. {
  40. app.UseExceptionHandler("/Home/Error");
  41. }
  42. app.UseRouting();
  43. //app.UseAuthorization();
  44. app.UseEndpoints(endpoints =>
  45. {
  46. endpoints.MapControllerRoute(
  47. name: "default",
  48. pattern: "{controller=Home}/{action=Index}/{id?}");
  49. });
  50. }
  51. }