IWebHostBuilderExtensions_VitConfig.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using Microsoft.AspNetCore.Hosting;
  2. using Microsoft.Extensions.DependencyInjection;
  3. using Microsoft.Extensions.Logging;
  4. using Newtonsoft.Json.Linq;
  5. namespace Vit.Extensions
  6. {
  7. public static class IWebHostBuilderExtensions_VitConfig
  8. {
  9. /// <summary>
  10. ///
  11. /// </summary>
  12. /// <param name="data"></param>
  13. /// <returns></returns>
  14. public static IWebHostBuilder UseVitConfig(this IWebHostBuilder data)
  15. {
  16. data.ConfigureServices(delegate (Microsoft.AspNetCore.Hosting.WebHostBuilderContext context, Microsoft.Extensions.DependencyInjection.IServiceCollection services)
  17. {
  18. services.Configure(delegate (Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions options)
  19. {
  20. //不限制body的大小
  21. options.Limits.MaxRequestBodySize = Vit.Core.Util.ConfigurationManager.ConfigurationManager
  22. .Instance.GetByPath<long?>("Vit.Kestrel.MaxRequestBodySize");
  23. });
  24. //解决Multipart body length limit 134217728 exceeded
  25. //services.Configure<Microsoft.AspNetCore.Http.Features.FormOptions>(x =>
  26. //{
  27. // x.ValueLengthLimit = int.MaxValue;
  28. // x.MultipartBodyLengthLimit = int.MaxValue; // In case of multipart
  29. //});
  30. });
  31. if (null == Vit.Core.Util.ConfigurationManager.ConfigurationManager.Instance.Get<JToken>("Logging"))
  32. {
  33. data.ConfigureLogging((Microsoft.Extensions.Logging.ILoggingBuilder logging) =>
  34. {
  35. logging.ClearProviders();
  36. });
  37. }
  38. return data;
  39. }
  40. }
  41. }