在IIS上部署一個能夠接受文件上傳的netCore WebApi,使用`Http`驗證時沒有任何問題,使用`SSL`後;經過微信小程序Post文件流,就會致使異常:`未顯示頁面 由於請求實體過大`的413 錯誤;可是在 Chrome 內核的微信小程序編輯工具中,則不存在該問題。
b.問題緣由
客戶端發起一個請求後,IIS會收到足以解析請求標頭的數據,但不會收到整個請求實體正文,若是發現須要客戶端證書時,將嘗試從新協商鏈接;但此時客戶端正等待向IIS發送請求中的其他數據。所以,若是讓客戶端能接受從新協商,則必須使用SSL預加載功能預加載請求實體正文,此時則可能引發默認設置值`UploadReadAheadSize`長度過小的問題。
c. 解決方案web
c.1 第一步:進入 `cd C:\Windows\System32\Inetsrv` 目錄執行命令行sql
appcmd.exe list config -section:system.webServer/serverRuntime // 查看當前設置的 UploadReadAheadSize 大小(byte)數據庫
appcmd.exe set config -section:system.webServer/serverruntime /uploadreadaheadsize:20480000 // 這個要設置夠大
小程序
c.2 第二步 還須要在web.config文件中更改上傳文件的大小c#
在建立的項目裏面是沒有 「web.config」 文件的。微信小程序
上傳大文件時須要配置下文件的大小,須要在 「config」 文件裏配置。建立一個或複製一個 「web.config」微信
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.webServer> <security> <requestFiltering> <!--單位:字節。 --> <requestLimits maxAllowedContentLength="1073741824" /> <!-- 1 GB --> </requestFiltering> </security> </system.webServer> </configuration>
<configuration> <system.web> <httpRuntime maxRequestLength="1048576" executionTimeout="3600" /> </system.web> <configuration>
<?xml version="1.0" encoding="utf-8"?> <!-- 有關如何配置 ASP.NET 應用程序的詳細信息,請訪問 https://go.microsoft.com/fwlink/?LinkId=301880 --> <configuration> <!--Mysql數據庫鏈接字符串--> <connectionStrings> <!--<add name="PNF_DB_Snapshot" connectionString="server=115.28.103.116;userid=chuxincms;pwd=chuxinmhanyinglong19900810_prod;port=3306;database=pnf_snapshot;sslmode=none;charset=utf8mb4;" />--> <add name="PNF_DB_Snapshot" connectionString="server=127.0.0.1;userid=root;pwd=snaphot!@#2019;port=3405;database=pnf_snapshot;sslmode=none;charset=utf8mb4;" /> </connectionStrings> <appSettings> <add key="Wechat_AppId" value="wx147013d69affee24" /> <add key="Wechat_Secret" value="e834dff786285d846fde8f71e76a3850" /> <add key="webpages:Version" value="3.0.0.0" /> <add key="webpages:Enabled" value="false" /> <add key="ClientValidationEnabled" value="true" /> <add key="UnobtrusiveJavaScriptEnabled" value="true" /> </appSettings> <system.web> <compilation debug="true" targetFramework="4.7.2" /> <httpRuntime targetFramework="4.7.2" maxRequestLength="1048576" executionTimeout="3600" /> <customErrors mode="Off" /> </system.web> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="0.0.0.0-5.2.7.0" newVersion="5.2.7.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="Microsoft.Extensions.Configuration.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-1.0.2.0" newVersion="1.0.2.0" /> </dependentAssembly> </assemblyBinding> </runtime> <system.codedom> <compilers> <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider,
Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" /> <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider,
Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4"
compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" /> </compilers> </system.codedom> <system.webServer> <httpRedirect enabled="false" destination="" /> <rewrite> <rules> <rule name="https" enabled="true" stopProcessing="true"> <match url="(.*)" /> <conditions logicalGrouping="MatchAny"> <add input="{HTTPS}" pattern="^OFF$" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" /> </rule> </rules> </rewrite> <staticContent> <mimeMap fileExtension=".woff2" mimeType="application/x-font-woff" /> </staticContent> <security> <requestFiltering> <!--單位:字節。 --> <requestLimits maxAllowedContentLength="1073741824" /> <!-- 1 GB --> </requestFiltering> </security> </system.webServer> </configuration> <!--ProjectGuid: CA844D14-20AE-45E5-B5D1-2502A0D14389-->