Max upload size for ASP.MVC CORE website

浪子不回头ぞ 提交于 2019-12-04 19:23:28

问题


How can I set maximum upload size for an ASP.NET CORE application?

In the past I was able to set it in web.config file like this:

<system.webServer>
    <security>
        <requestFiltering>
            <requestLimits maxAllowedContentLength="52428800" />
        </requestFiltering>
    </security>
</system.webServer>

回答1:


Two ways to do that:

1.Using application wise settings - in the > configure services method.

services.Configure<FormOptions>(options =>
{
    options.MultipartBodyLengthLimit = 52428800;
});

2.Using RequestFormSizeLimit attribute - for specific actions. - It is not yet available in official package Unofficial




回答2:


You can configure the max limit for multipart uploads in the ConfigureServices method:

public void ConfigureServices(IServiceCollection services)
{
    services.Configure<FormOptions>(options =>
    {
        options.MultipartBodyLengthLimit = 52428800;

    });

    services.AddMvc();
}

You can also configure the MaxRequestBufferSize by using services.Configure<KestrelServerOptions>, but it looks like this is going to be deprecated in the next release.



来源:https://stackoverflow.com/questions/40264474/max-upload-size-for-asp-mvc-core-website

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!