ASP.net中HttpRequest最大长度超出问题

时间:2010-05-18 18:11:28

标签: asp.net vb.net httprequest

我正在尝试修复我支持的应用程序的问题(我没有编写代码)。该代码采用SSRS报告并以pdf格式呈现。用户偶尔会收到标题中指出的错误。生成错误时没有押韵或理由(特定报告将运行一次并在下一次抛出错误)。代码如下。

  Public Sub OpenReport()
        Dim MyParms As New Generic.List(Of ReportParameter)
        Dim mimeType As String = Nothing
        Dim encoding As String = Nothing
        Dim extension As String = Nothing
        Dim deviceInfo As String = Nothing
        Dim streamids() As String = Nothing
        Dim warnings As Microsoft.Reporting.WebForms.Warning() = Nothing
        Dim bytes() As Byte 
        Dim format As String = "PDF" ''#to open the report in pdf; report viewer invisible

        Try
            If dropReports.SelectedItem.Value = "1" Then

                If Session("IsBDAP") = True Then
                    MyParms.Add(New ReportParameter("SCAId", dropSCA.SelectedItem.Value, False))
                Else
                    MyParms.Add(New ReportParameter("SCAId", Server.UrlEncode(Session("SCAId")), False))
                End If
                MyParms.Add(New ReportParameter("ProviderId", dropProvider.SelectedItem.Value, False))
                If dropVisit.Visible = True Then
                    MyParms.Add(New ReportParameter("VisitId", dropVisit.SelectedItem.Value, False))
                End If
                MyParms.Add(New ReportParameter("FY", dropContractFY.SelectedItem.Value, False))

                ReportViewer1.ProcessingMode = ProcessingMode.Remote
                ReportViewer1.ServerReport.ReportServerUrl = New Uri(System.Configuration.ConfigurationManager.AppSettings("ReportServerURI"))
                ReportViewer1.ServerReport.ReportPath = Session("ReportsFolder") & "MReport"
                ReportViewer1.ServerReport.ReportServerCredentials = New MyReportServerCredentials()
                ReportViewer1.ServerReport.SetParameters(MyParms)
                ''#Code to convert the report to pdf 
                deviceInfo = "<DeviceInfo>" + "<SimplePageHeaders>True</SimplePageHeaders>" + "</DeviceInfo>"
                bytes = ReportViewer1.ServerReport.Render(format, deviceInfo, mimeType, encoding, extension, streamids, warnings)
                Dim size As Integer = bytes.Length
                ReportViewer1.ServerReport.Refresh()
                Response.Buffer = True
                Response.Clear()
                Response.ContentType = mimeType
                Response.AddHeader("content-disposition", "attachment; filename=MReport." + extension)
                Response.BinaryWrite(bytes)


            ElseIf dropReports.SelectedItem.Value = "2" Then

                If Session("IsBDAP") = True Then
                    MyParms.Add(New ReportParameter("SCAId", dropSCA.SelectedItem.Value, False))
                Else
                    MyParms.Add(New ReportParameter("SCAId", Server.UrlEncode(Session("SCAId")), False))
                End If
                MyParms.Add(New ReportParameter("ProviderId", dropProvider.SelectedItem.Value, False))
                If dropVisit.Visible = True Then
                    MyParms.Add(New ReportParameter("FollowUpVisitId", dropVisit.SelectedItem.Value, False))
                End If
                MyParms.Add(New ReportParameter("FY", dropContractFY.SelectedItem.Value, False))

                ReportViewer1.ProcessingMode = ProcessingMode.Remote
                ReportViewer1.ServerReport.ReportServerUrl = New Uri(System.Configuration.ConfigurationManager.AppSettings("ReportServerURI"))
                ReportViewer1.ServerReport.ReportPath = Session("ReportsFolder") & "FReport"
                ReportViewer1.ServerReport.ReportServerCredentials = New MyReportServerCredentials()
                ReportViewer1.ServerReport.SetParameters(MyParms)
                ''#Code to convert the report to pdf 
                deviceInfo = "<DeviceInfo>" + "<SimplePageHeaders>True</SimplePageHeaders>" + "</DeviceInfo>"
                bytes = ReportViewer1.ServerReport.Render(format, deviceInfo, mimeType, encoding, extension, streamids, warnings)
                ReportViewer1.ServerReport.Refresh()
                Response.Buffer = True
                Response.Clear()
                Response.ContentType = mimeType
                Response.AddHeader("content-disposition", "attachment; filename=FReport." + extension)
                Response.BinaryWrite(bytes)

我读到默认长度限制是4MB。这些报告本身都不超过350K。我想知道这是否可能是由缓存问题引起的。我不是专家,所以我需要一些指导,以便最好地解决问题。我也想了解问题发生的原因。请注意,代码段中只显示了2个报告 - 完整子记录中有大约30个报告。

感谢您的帮助。

编辑 - 我尝试了提议的解决方案,但它没有帮助(我也尝试了Fiddler路线,但没有看到任何明显的东西)。我认为最好澄清一下。报告将运行一段时间,但执行时间逐渐变慢,直到应用程序最终显示错误。这是否解决了这个问题?

TIA

3 个答案:

答案 0 :(得分:3)

尝试在web.config中增加以下值:

<httpRuntime maxRequestLength="204800" requestLengthDiskThreshold="204800" />

答案 1 :(得分:1)

好的,我终于弄清楚了......这是原因(对于任何有类似问题的人)。问题是viewstate。页面上的reportviewer正在向viewstate添加数百万个字节,从而导致问题。我为隐藏的reportviewer禁用了viewstate,不再有问题。感谢大家的帮助和建议。

答案 2 :(得分:0)

您是否尝试过记录请求网址以查看它们是否正在增长?也许它是某个地方,“ReportsFolder”会话值或某个地方被误解的扩展名将是我的猜测。