ユーザーがファイルをアップロードできるようにするaspxページがあり、ファイルの最大アップロードサイズを10MBに制限したいと思います。IIS7、.NET3.5。web.configファイルで次の設定を行っています。
<location path="foo.aspx">
<system.web>
<!-- maxRequestLength: kbytes, executionTimeout:seconds -->
<httpRuntime maxRequestLength="10240" executionTimeout="120" />
<authorization>
<allow roles="customRole"/>
<!-- Deny everyone else -->
<deny users="*"/>
</authorization>
</system.web>
<system.webServer>
<security>
<requestFiltering>
<!-- maxAllowedContentLength: bytes -->
<requestLimits maxAllowedContentLength="10240000"/>
</requestFiltering>
</security>
<handlers accessPolicy="Read, Script">
<add name="foo" path="foo.aspx" verb="POST"
type="System.Web.UI.PageHandlerFactory"
preCondition="integratedMode" />
</handlers>
</system.webServer>
</location>
を実装するカスタムエラー処理モジュールがありますIHttpModule
。私はmaxRequestLength
、超えたときHttpApplication.Error
に実際に発生することを発見しました。ただし、で遊んでいるとmaxAllowedContentLength
、HttpApplication.Error
イベントが発生せず、ユーザーは404.13ページにリダイレクトされます。最初のチャンスの例外をオンにしてVisualStudioに接続しましたが、何もスローされていません。
私の最初の考えは、以前のイベントでヘッダーコンテンツの長さを確認することです。これを行う場所に関する推奨事項/ベストプラクティスはありますか?PostLogRequest?EndRequest?