Program.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using Microsoft.AspNetCore.Builder;
  2. using Microsoft.AspNetCore.Hosting;
  3. using Microsoft.Extensions.DependencyInjection;
  4. using Vit.Extensions; //---- add code 1
  5. namespace App
  6. {
  7. public class Program
  8. {
  9. public static void Main(string[] args)
  10. {
  11. var builder = WebApplication.CreateBuilder(args);
  12. #region #1 config WebHost
  13. {
  14. builder.WebHost
  15. .TryUseSerslot() //---- add code 2
  16. .UseUrls(Vit.Core.Util.ConfigurationManager.Appsettings.json.GetByPath<string[]>("server.urls")) //---- add code 3
  17. ;
  18. }
  19. #endregion
  20. #region ##2 Add services to the container.
  21. {
  22. builder.Services.AddControllers()
  23. .AddJsonOptions(options =>
  24. {
  25. //Json Serialize config
  26. options.JsonSerializerOptions.AddConverter_Newtonsoft();
  27. options.JsonSerializerOptions.AddConverter_DateTime();
  28. options.JsonSerializerOptions.IncludeFields = true;
  29. // JsonNamingPolicy.CamelCase makes the first letter lowercase (default), null leaves case unchanged
  30. options.JsonSerializerOptions.PropertyNamingPolicy = null;
  31. // set the JSON encoder to allow all Unicode characters, preventing the default behavior of encoding non-ASCII characters.
  32. options.JsonSerializerOptions.Encoder = System.Text.Encodings.Web.JavaScriptEncoder.Create(System.Text.Unicode.UnicodeRanges.All);
  33. // Ignore null values
  34. options.JsonSerializerOptions.DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull;
  35. // extra comma at the end of a list of JSON values in an object or array is allowed (and ignored) within the JSON payload being deserialized.
  36. options.JsonSerializerOptions.AllowTrailingCommas = true;
  37. });
  38. }
  39. #endregion
  40. var app = builder.Build();
  41. //app.UseAuthorization();
  42. app.MapControllers();
  43. app.Run();
  44. }
  45. }
  46. }