涓€銆佺畝浠?/span>
銆€銆€鍦ˋSP.NET Core MVC涓?鏂囦欢涓婁紶鐨勬渶澶т笂浼犳枃浠堕粯璁や负20MB,濡傛灉鎴戜滑鎯充笂浼犱竴浜涙瘮杈冨ぇ鐨勬枃浠讹紝灏变笉鐭ラ亾鎬庝箞鍘昏缃簡锛屾病鏈変簡Web.Config鎴戜滑搴旇濡備綍涓嬫墜鍛紵
浜屻€佽缃笂浼犳枃浠跺ぇ灏?/span>
銆€銆€1.搴旂敤绋嬪簭绾у埆璁剧疆
銆€銆€銆€銆€鎴戜滑闇€瑕佸湪 ConfigureServices鏂规硶涓坊鍔犲涓嬩唬鐮侊紝璁剧疆鏂囦欢涓婁紶鐨勫ぇ灏忛檺鍒朵负60 MB銆?/span>
public void ConfigureServices(IServiceCollection services) { services.Configure<FormOptions>(options => { options.MultipartBodyLengthLimit = 60000000; }); }
銆€銆€2.Action绾у埆璁剧疆
銆€銆€銆€銆€闄や簡涓婇潰瀵瑰叏灞€杩涜璁剧疆澶栵紝鎴戜滑涔熷彲浠ラ€氳繃鑷畾涔塅ilter鐨勬柟寮忥紝瀵瑰崟涓狝ction杩涜鎺у埗锛孎ilter浠g爜濡備笅锛?/span>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] public class RequestFormSizeLimitAttribute : Attribute, IAuthorizationFilter, IOrderedFilter { private readonly FormOptions _formOptions; public RequestFormSizeLimitAttribute(int valueCountLimit) { _formOptions = new FormOptions() { ValueCountLimit = valueCountLimit }; } public int Order { get; set; } public void OnAuthorization(AuthorizationFilterContext context) { var features = context.HttpContext.Features; var formFeature = features.Get<IFormFeature>(); if (formFeature == null || formFeature.Form == null) { // Request form has not been read yet, so set the limits features.Set<IFormFeature>(new FormFeature(context.HttpContext.Request, _formOptions)); } } }
銆€銆€銆€鍥犱负ASP.NET Core MVC涓紝涓庝箣鍓嶇増鏈笉鍚岀殑鏄叿浣撳姛鑳借灏佽鍦ㄤ簡鍚勭Feature锛堢壒寰侊級涓紝HttpContext涓婁笅鏂囧彧鏄兘鍚勪釜鐗瑰緛杩涜绠$悊鐨勫鍣ㄣ€傝繖涓狥ilter涓氨鍙皢Action鎷︽埅锛屽HttpContext涓殑FormFeature锛堣礋璐h〃鍗曟彁浜ゅ姛鑳斤級閲嶆柊杩涜璁剧疆锛屼粠鑰岃揪鍒伴檺鍒跺叿浣揂ction涓婁紶鏂囦欢澶у皬鐨勭洰鐨勩€?/span>
涓夈€佺粨璇?/span>
銆€銆€銆€鏈潵鎰熻鍍忔槸鍙戠幇浜嗕竴涓枃浠朵笂浼犵殑BUG锛屽凡缁忕‘璁ゅ湪1.0.1鐗堟湰涓凡缁忚繘琛屼簡淇銆傚湪1.0.0鐗堟湰涓紝濡傛灉Action娌℃湁璁剧疆涓€涓狪FromFile浣滀负鍙傛暟锛岄偅涔圧equest.From.Files灏嗕笉鑳借闂苟涓旀姤鍑哄紓甯搞€?/span>
GitHub锛歨ttps://github.com/maxzhang1985/YOYOFx 濡傛灉瑙夎繕鍙互璇?strong>Star涓嬶紝 娆㈣繋涓€璧蜂氦娴併€?/span>
.NET Core 寮€婧愬涔犵兢锛?nbsp;214741894