• <small id='WOA05'></small><noframes id='WOA05'>

    1. <i id='WOA05'><tr id='WOA05'><dt id='WOA05'><q id='WOA05'><span id='WOA05'><b id='WOA05'><form id='WOA05'><ins id='WOA05'></ins><ul id='WOA05'></ul><sub id='WOA05'></sub></form><legend id='WOA05'></legend><bdo id='WOA05'><pre id='WOA05'><center id='WOA05'></center></pre></bdo></b><th id='WOA05'></th></span></q></dt></tr></i><div id='WOA05'><tfoot id='WOA05'></tfoot><dl id='WOA05'><fieldset id='WOA05'></fieldset></dl></div>

        <bdo id='WOA05'></bdo><ul id='WOA05'></ul>

      <legend id='WOA05'><style id='WOA05'><dir id='WOA05'><q id='WOA05'></q></dir></style></legend>

      1. <tfoot id='WOA05'></tfoot>

        在 Asp.Net 核心中增加上传文件的大小

        时间:2023-06-08
          <legend id='C6BGZ'><style id='C6BGZ'><dir id='C6BGZ'><q id='C6BGZ'></q></dir></style></legend>
              <tbody id='C6BGZ'></tbody>
              <bdo id='C6BGZ'></bdo><ul id='C6BGZ'></ul>
            • <i id='C6BGZ'><tr id='C6BGZ'><dt id='C6BGZ'><q id='C6BGZ'><span id='C6BGZ'><b id='C6BGZ'><form id='C6BGZ'><ins id='C6BGZ'></ins><ul id='C6BGZ'></ul><sub id='C6BGZ'></sub></form><legend id='C6BGZ'></legend><bdo id='C6BGZ'><pre id='C6BGZ'><center id='C6BGZ'></center></pre></bdo></b><th id='C6BGZ'></th></span></q></dt></tr></i><div id='C6BGZ'><tfoot id='C6BGZ'></tfoot><dl id='C6BGZ'><fieldset id='C6BGZ'></fieldset></dl></div>

              <tfoot id='C6BGZ'></tfoot>

              <small id='C6BGZ'></small><noframes id='C6BGZ'>

                  本文介绍了在 Asp.Net 核心中增加上传文件的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  目前,我正在使用 Asp.Net Core 和 MVC6 需要上传文件大小不受限制.我已经搜索了它的解决方案,但仍然没有得到实际的答案.

                  Currently, I am working with Asp.Net Core and MVC6 need to upload file size unlimited. I have searched its solution but still not getting the actual answer.

                  我试过这个链接

                  如果有人有任何想法,请帮忙.

                  If anyone have any idea please help.

                  谢谢.

                  推荐答案

                  其他答案解决IIS限制.但是,从 ASP.NET Core 2.0 开始,Kestrel 服务器也施加了自己的默认限制.

                  The other answers solve the IIS restriction. However, as of ASP.NET Core 2.0, Kestrel server also imposes its own default limits.

                  Github of KestrelServerLimits.cs

                  关于请求正文大小限制和解决方案的公告(引用如下)

                  如果要更改特定 MVC 操作或控制器的最大请求正文大小限制,可以使用 RequestSizeLimit 属性.以下将允许 MyAction 接受最多 100,000,000 字节的请求正文.

                  If you want to change the max request body size limit for a specific MVC action or controller, you can use the RequestSizeLimit attribute. The following would allow MyAction to accept request bodies up to 100,000,000 bytes.

                  [HttpPost]
                  [RequestSizeLimit(100_000_000)]
                  public IActionResult MyAction([FromBody] MyViewModel data)
                  {
                  

                  [DisableRequestSizeLimit] 可用于使请求大小不受限制.这有效地恢复了仅属性操作或控制器的 2.0.0 之前的行为.

                  [DisableRequestSizeLimit] can be used to make request size unlimited. This effectively restores pre-2.0.0 behavior for just the attributed action or controller.

                  如果请求未由 MVC 操作处理,则仍可以使用 IHttpMaxRequestBodySizeFeature 在每个请求的基础上修改限制.例如:

                  If the request is not being handled by an MVC action, the limit can still be modified on a per request basis using the IHttpMaxRequestBodySizeFeature. For example:

                  app.Run(async context =>
                  {
                      context.Features.Get<IHttpMaxRequestBodySizeFeature>().MaxRequestBodySize = 100_000_000;
                  

                  MaxRequestBodySize 是一个可为空的 long.将其设置为 null 会禁用类似 MVC 的 [DisableRequestSizeLimit] 的限制.

                  MaxRequestBodySize is a nullable long. Setting it to null disables the limit like MVC's [DisableRequestSizeLimit].

                  您只能在应用程序尚未开始读取时配置请求的限制;否则抛出异常.有一个 IsReadOnly 属性告诉您 MaxRequestBodySize 属性是否处于只读状态,这意味着配置限制为时已晚.

                  You can only configure the limit on a request if the application hasn’t started reading yet; otherwise an exception is thrown. There’s an IsReadOnly property that tells you if the MaxRequestBodySize property is in read-only state, meaning it’s too late to configure the limit.

                  如果要全局修改最大请求正文大小,可以通过修改 UseKestrelUseHttpSys<回调中的 MaxRequestBodySize 属性来完成/代码>.MaxRequestBodySize 在这两种情况下都是可以为空的 long.例如:

                  If you want to modify the max request body size globally, this can be done by modifying a MaxRequestBodySize property in the callback of either UseKestrel or UseHttpSys. MaxRequestBodySize is a nullable long in both cases. For example:

                  .UseKestrel(options =>
                  {
                      options.Limits.MaxRequestBodySize = null;
                  

                  .UseHttpSys(options =>
                  {
                      options.MaxRequestBodySize = 100_000_000;
                  

                  这篇关于在 Asp.Net 核心中增加上传文件的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                1. <small id='BUHHP'></small><noframes id='BUHHP'>

                    <bdo id='BUHHP'></bdo><ul id='BUHHP'></ul>
                  • <tfoot id='BUHHP'></tfoot>
                  • <i id='BUHHP'><tr id='BUHHP'><dt id='BUHHP'><q id='BUHHP'><span id='BUHHP'><b id='BUHHP'><form id='BUHHP'><ins id='BUHHP'></ins><ul id='BUHHP'></ul><sub id='BUHHP'></sub></form><legend id='BUHHP'></legend><bdo id='BUHHP'><pre id='BUHHP'><center id='BUHHP'></center></pre></bdo></b><th id='BUHHP'></th></span></q></dt></tr></i><div id='BUHHP'><tfoot id='BUHHP'></tfoot><dl id='BUHHP'><fieldset id='BUHHP'></fieldset></dl></div>

                        <tbody id='BUHHP'></tbody>
                        <legend id='BUHHP'><style id='BUHHP'><dir id='BUHHP'><q id='BUHHP'></q></dir></style></legend>