close

哈哈, 先笑一笑 , 事情比較容易解決. 以前同事遇到Bug 還說回家睡一晚Bug 就會不見, 這種事還沒發生在我身上.

今天測試 .net core API 接收大量資料欲 50 M , 一直收到 404.  

.net core 程式 Debug Mode 跑在 IIS Express 上, 還以為新增 Controller 有問題.

先看AP Log : AP 沒Log , 還沒到Controller

再看IIS Express Log : $UserProfile$\Documents\IISExpress\Logs\XXX\

[2019-11-14 03:28:49 ::1 POST /Import - 42444 - ::1 - - 404 13 0 81]

~ 啊,是 404.13, 應該是長度過長 , 換小檔試試 ~ YA! Pass!

~換 denet run 也Pass, 大檔也沒限制

喔喔喔! 調整IIS Express 系統設定吧!

1. applicationhost.config

  <system.webServer> 
    <security>
      <requestFiltering>
        <!-- 100MB-->
        <requestLimits maxAllowedContentLength="104857600"></requestLimits>
      </requestFiltering>
    </security>

404.13 Not Found.404.13 Not Found.404.13 Not Found. 

2. 放大絕改系統值

C:\Program Files \IIS Express\config\schema\IIS_schema.xml 

找到他, 改變他,

<element name="requestLimits"><attribute name="maxAllowedContentLength" type="uint" defaultValue="100000000" />

 

YA! Pass! IIS 應改也可,但會引響整個Server 全部網站 設定 , 回復 30 M 設定 .. OOXX

3. IISExpress 會吃 Web.Config 吧! ASP.NET Core 加 Web.Config 看看

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

YA! Pass!  , 只是 .Net Core 還在Web.Config  遜遜遜

4. .Net Core Run

上傳大小

[RequestSizeLimit(40000000)]
public async Task<IActionResult> API( )

 

[HttpPost]
[DisableRequestSizeLimit]
public async Task<IActionResult> API( )
{
   
}

Global setting

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
    .UseStartup<Startup>()
    .UseKestrel(options =>
    {
        options.Limits.MaxRequestBodySize = 50000000; //50MB
    });
}

Middleware setting

1
2
3
4
5
app.UseWhen(context => context.Request.Path.StartsWithSegments("/api"), appBuilder =>
{
    context.Features.Get<IHttpMaxRequestBodySizeFeature>().MaxRequestBodySize = null;
   
});

 

收工, 繼續種碼

arrow
arrow
    文章標籤
    ASP.NET Core
    全站熱搜
    創作者介紹
    創作者 Peter Huang 的頭像
    Peter Huang

    金面大叔的部落格

    Peter Huang 發表在 痞客邦 留言(0) 人氣()