1

サイズが 9 MB のドキュメントをアップロードしようとすると、「最大長を超えました」というエラーが発生します。httpRuntime maxRequestLengthと web.config を増やすと問題が解決することはわかっていますrequestLengthDiskThresholdが、私が探しているのは、エラーを適切に処理してユーザーにメッセージを表示する方法です。グローバル ascx で Application_Error イベントを使用しようとしましたが、イベントが発生しません。Server.Transferその理由は、DNN PageBaseクラスのOnErrorメソッドにある可能性があります。
仕様:

  • ネット 3.5 SP1 (ASP.NET)
  • IIS6
  • DotNetNuke 5.4.4(2)

それは非常に緊急であり、あなたの提案は大歓迎です。ありがとう

4

1 に答える 1

2

数か月前に同様の問題がありました。この投稿は非常に役に立ちました: http://www.velocityreviews.com/forums/showpost.php?p=3794467&postcount=8

基本的に、global.asax 分離コードにコードを追加して、すべてのページ リクエストをスニッフィングします。ファイルが添付されている場合、実際のページへのアップロードが行われる前にファイル サイズがチェックされます。チャンピオンのように機能します。

私はVBでそれが必要だったので、あなたもそうする場合に備えて..変換を保存します;)

Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)

    Dim runtime As System.Web.Configuration.HttpRuntimeSection = System.Web.Configuration.WebConfigurationManager.GetSection("system.web/httpRuntime")
    Dim maxRequestLength As Integer = (runtime.MaxRequestLength - 100) * 1024

    Dim context As HttpContext = CType(sender, HttpApplication).Context

    If context.Request.ContentLength > maxRequestLength Then
        Dim pro As IServiceProvider = CType(context, IServiceProvider)
        Dim workerRequest As HttpWorkerRequest = DirectCast(pro.GetService(GetType(HttpWorkerRequest)), HttpWorkerRequest)

        If workerRequest.HasEntityBody Then
            Dim requestLength As Integer = workerRequest.GetTotalEntityBodyLength

            Dim initialBytes As Integer = 0

            If workerRequest.GetPreloadedEntityBody IsNot Nothing Then initialBytes = workerRequest.GetPreloadedEntityBody.Length

            If Not workerRequest.IsEntireEntityBodyIsPreloaded Then
                Dim buffer As Byte() = New Byte(511999) {}
                Dim receivedBytes As Integer = initialBytes

                While (requestLength - receivedBytes) >= initialBytes
                    initialBytes = workerRequest.ReadEntityBody(buffer, buffer.Length)
                    receivedBytes += initialBytes

                End While
                initialBytes = workerRequest.ReadEntityBody(buffer, requestLength - receivedBytes)
            End If

            Response.Redirect("~/errorPages/MaxLength.htm")

        End If
    End If



End Sub
于 2010-12-23T14:33:06.907 に答える