티스토리 뷰

반응형

[asp.net/.netcore] asp.net에서 파일 업로드 시 대용량(large) 파일 업로드 하는 방법(asp.net request body too large 해결법)

기준 버전 .NET Core 3.1 

 

#기본적으로 asp.net에서는 30mb이상의 파일업로드가 불가능하여 제약을 풀어야한다.

 

#[web.config] - 용량제한을 1GB 이상으로 올려준다.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
	<system.webServer>
		<security>
			<requestFiltering>
				<requestLimits maxAllowedContentLength="1073741824" />
			</requestFiltering>
		</security>
	</system.webServer>
</configuration>

 

#[Startup.cs] - 각 환경별로 제약을 풀어준다

 public void ConfigureServices(IServiceCollection services)
        {
         services.AddDistributedMemoryCache();
          services.Configure<FormOptions>(x =>
            {
                x.ValueLengthLimit = int.MaxValue;
                x.MultipartBodyLengthLimit = int.MaxValue;
                x.MultipartHeadersLengthLimit = int.MaxValue;
            });
            services.Configure<IISServerOptions>(options =>
            {
                options.MaxRequestBodySize = int.MaxValue;
            });
            services.Configure<KestrelServerOptions>(options =>
            {
                options.Limits.MaxRequestBodySize = int.MaxValue;
            });
        }
        
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
        app.UseStaticFiles();
        }

 

#[Controller.cs] 각 컨트롤러에 요청 시 리밋을 명시해준다

   [Route("SaveFile")]
        [RequestSizeLimit(1073741824)]
        [RequestFormLimits(MultipartBodyLengthLimit = 1073741824)]
        [HttpPost]
        public JsonResult SaveFile()
        {
        }

Controller.cs]

 

 

#asp.net #.net core #c# #limit #large #too #asp.net request body too large 

반응형
댓글
반응형