IWebHostBuilderExtensions_VitConfig.cs 1.4 KB

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