Azure App Serviceのアップロード可能なファイルサイズを変更する方法

Higtyのシステムの作り方

Azure App Serviceのアップロード可能なファイルサイズを変更する方法について簡単に解説です。

Program.csでIHttpMaxRequestBodySizeFeatureクラスを使用して以下のように処理を書きます。




app.Use(async (context, next) => 
{
    var f = context.Features.Get<IHttpMaxRequestBodySizeFeature>();
    if (f != null)
    {
        try
        {
            f.MaxRequestBodySize = 1 * (Int32)Math.Pow(1024, 3);//1GB
        }
        catch (Exception ex)
        {
        }
    }


web.configにも設定します。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
	<location path="." inheritInChildApplications="false">
		<system.webServer>
			<handlers>
				<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
			</handlers>
			<aspNetCore processPath="dotnet" arguments=".\HigLaboApp.WebApp.dll" stdoutLogEnabled="false" stdoutLogFile="\\?\%home%\LogFiles\stdout" hostingModel="inprocess" />
		</system.webServer>
	</location>
	<system.webServer>
		<security>
			<requestFiltering>
				<!-- maxAllowedContentLength はバイト単位で指定 -->
				<requestLimits maxAllowedContentLength="104857600" />
				<!-- 100 MB -->
			</requestFiltering>
		</security>
	</system.webServer>
</configuration>