-
[asp.net / asp.net core] HttpException (0x80004005) : 최대 요청 길이를 초과했습니다 파일 업로드 에러C#(asp.net | asp.net core) 2021. 7. 7. 14:37728x90
asp.net 파일 업로드를 할 때 용량이 크면 나오는 에러이다
해결하는 방법은 web.config 에서 아래 코드를 추가해주면된다
우선 httpRuntime 코드를 Ctrl + F 로 찾아서 최대 용량을 100MB 로 바꿔준다
<httpRuntime targetFramework="4.5.2" maxRequestLength="104857600"/>
그리고 configuration 코드가 닫기 전 윗 줄에 코드를 추가한다
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="104857600"/>
</requestFiltering>
</security>
</system.webServer>
</configuration>서버를 껐다가 다시 키면 이제 100MB 까지는 파일이 업로드가 될 것이다
asp.net core 일때를 알아보자
asp.net core 프로젝트를 생성하면 web.config 라는 파일이 안보인다
프로젝트 > Add > New Item > XML File 을 클릭한 후 web.config 파일을 생성한다
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.web> <httpRuntime maxRequestLength="1048576" /> </system.web> <system.webServer> <security> <requestFiltering> <requestLimits maxAllowedContentLength="2147483648" /> </requestFiltering> </security> </system.webServer> </configuration>
web.config 파일에 위 코드를 입력해준다
마지막으로 Startup.cs에 코드를 입력해부면 2GB까지 파일 업로드가 가능하다
public void ConfigureServices(IServiceCollection services) { services.Configure<FormOptions>(x => { x.ValueLengthLimit = int.MaxValue; x.MultipartBodyLengthLimit = int.MaxValue; }); }
728x90728x90'C#(asp.net | asp.net core)' 카테고리의 다른 글
C# state operation | record 사용법 (0) 2021.08.09 [C#] Web Form cs에서 javaScript 사용하기(alert) (0) 2021.07.13 [asp.net core] EntityFramwork Core Oracle 연동하기 (0) 2021.07.09 Visual Studio C#에서 폴더 탐색창, 파일 탐색창 띄우기 (0) 2020.10.30