增加 Azure Web 服务/Razor 页面的上传限制
Increase upload limit on Azure Web Service / Razor Pages
我有一个带有文件上传页面的 Razor Pages 应用程序。我想在该页面上最多允许上传 60 MB。我可以通过向 .vs
目录中的本地 applicationhost.config
文件添加 <requestLimits maxAllowedContentLength="62914560" />
标记来在本地执行此操作,但这对部署没有帮助。
这是我试过的方法
- 将
[RequestFormLimits(MultipartBodyLengthLimit = 60 * 1024 * 1024)]
和 [RequestSizeLimit(60 * 1024 * 1024)]
添加到相关页面的 PageModel
- 将
services.Configure<FormOptions>(options => { options.MultipartBodyLengthLimit = 60 * 1024 * 1024; });
添加到我的 Startup.cs
- 使用
app.UseWhen(context => context.Request.Path.StartsWithSegments("/mypagepath"), appBuilder => { appBuilder.Features.Get<IHttpMaxRequestBodySizeFeature>().MaxRequestBodySize = null; });
添加中间件处理程序
- 使用
<requestLimits>
标签将 Web.config
文件添加到项目的根目录。如果我部署该文件,整个应用程序将停止工作。
一切都在本地运行,但是当我部署到我的 Azure 应用服务时,出现此错误
The page was not displayed because the request entity is too large.
如果添加 web.config
文件,则无需在代码中添加任何内容。
在.net core项目中,你也可以使用web.config
文件。
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="62914560" /> <!--60MB-->
</requestFiltering>
</security>
</system.webServer>
我有一个带有文件上传页面的 Razor Pages 应用程序。我想在该页面上最多允许上传 60 MB。我可以通过向 .vs
目录中的本地 applicationhost.config
文件添加 <requestLimits maxAllowedContentLength="62914560" />
标记来在本地执行此操作,但这对部署没有帮助。
这是我试过的方法
- 将
[RequestFormLimits(MultipartBodyLengthLimit = 60 * 1024 * 1024)]
和[RequestSizeLimit(60 * 1024 * 1024)]
添加到相关页面的PageModel
- 将
services.Configure<FormOptions>(options => { options.MultipartBodyLengthLimit = 60 * 1024 * 1024; });
添加到我的Startup.cs
- 使用
app.UseWhen(context => context.Request.Path.StartsWithSegments("/mypagepath"), appBuilder => { appBuilder.Features.Get<IHttpMaxRequestBodySizeFeature>().MaxRequestBodySize = null; });
添加中间件处理程序
- 使用
<requestLimits>
标签将Web.config
文件添加到项目的根目录。如果我部署该文件,整个应用程序将停止工作。
一切都在本地运行,但是当我部署到我的 Azure 应用服务时,出现此错误
The page was not displayed because the request entity is too large.
如果添加 web.config
文件,则无需在代码中添加任何内容。
在.net core项目中,你也可以使用web.config
文件。
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="62914560" /> <!--60MB-->
</requestFiltering>
</security>
</system.webServer>