代码之家  ›  专栏  ›  技术社区  ›  cjibo

iis7 response.writebuffer不工作

  •  0
  • cjibo  · 技术社区  · 17 年前

    我们有一个ASP.NET1.1应用程序,它使用CrystalReports输出一个Excel电子表格。这些代码在iis6下工作,但是当我们试图将其迁移到iis7时,它将弹出没有内容的html,而不是excel文件。

    MIME类型存在。下面是我们正在使用的代码。我没有写这段代码,因为我现在主要在3.5框架中工作。我的假设是我在iis7配置中遗漏了一些东西,而不是代码,因为它在iis6上工作。net 1.1应用程序的其余部分在iis7上工作。

            Dim cr As ReportClass
            'EXPORT the report based on the export type passed in.
            Dim ExpOptions As New ExportOptions
            Dim ContentType As String
            Dim strExt As String
            Trace.Write("DisplayReport reportname=" + ReportName + " SQL=" + SQL + " SQLSub1=" + Convert.ToString(Session("SQLSub1")))
            'Get the report filled with the data.
            If Session("SQLSub1") <> "" Then
                If Not Session("SubRptName") Is Nothing Then
                    cr = PopulateReport(GetReportObject(ReportName), SQL, Session("SQLSub1"), Session("SubRptName"))
                    Session("SQLSub1") = ""
                    Session("SubRptName") = Nothing
                Else
                    cr = PopulateReport(GetReportObject(ReportName), SQL, Session("SQLSub1"))
                    Session("SQLSub1") = ""
                End If
            Else
                cr = PopulateReport(GetReportObject(ReportName), SQL)
            End If
    
            If DisplayType = ReportType.Excel Then
                If ReportName.ToUpper = "ACTION" Or ReportName.ToUpper = "INVENTORY_EXCEL" _
                    Or ReportName.ToUpper = "UNDERPERFORM" Or ReportName.ToUpper = "EMPLOYEE_EXCEL" Then
                    Dim excelFormatOpts As New ExcelFormatOptions
                    ' Set the excel format options.
                    excelFormatOpts.ExcelTabHasColumnHeadings = True
                    excelFormatOpts.ExcelUseConstantColumnWidth = False
                    ExpOptions.FormatOptions = excelFormatOpts
                Else
                    ExpOptions.FormatOptions = New ExcelFormatOptions
                End If
                ExpOptions.ExportFormatType = ExportFormatType.Excel
                ContentType = "application/vnd.ms-excel"
                strExt = ".xls"
            ElseIf DisplayType = ReportType.PDF Then
                ExpOptions.ExportFormatType = ExportFormatType.PortableDocFormat
                ExpOptions.FormatOptions = New PdfRtfWordFormatOptions
                ContentType = "application/pdf"
                strExt = ".pdf"
            End If
    
            'Stream the report to the screen
            Dim req As New ExportRequestContext
            req.ExportInfo = ExpOptions
    
            Dim s As Stream
            Try
                s = cr.FormatEngine.ExportToStream(req)
            Catch ex As Exception
                Trace.Warn("DisplayReport cr.FormatEngine.ExportToStream(req) failed: " + ex.Message)
                Dim x As String = String.Empty
            End Try
    
    
            Response.Clear()
            'Response.ClearHeaders()
            'Response.ClearContent()
            Response.Buffer = True
            Response.ContentType = ContentType
            Response.AddHeader("Content-Type", ContentType)
    
    
            Dim buffer(s.Length) As Byte
            s.Read(buffer, 0, Int(s.Length))
            Response.BinaryWrite(buffer)
    
            Dim strContentDisposition As String = "inline;filename=" & ReportName.ToString.ToLower & strExt.ToString
            Trace.Write("DisplayReport strContentDisposition=" + strContentDisposition)
            Response.AddHeader("Content-Disposition", strContentDisposition)
            Response.Cache.SetMaxAge(New TimeSpan(0, 0, 10))
            Response.End()
    
    1 回复  |  直到 17 年前
        1
  •  0
  •   Jake RohdeJake Rohde    17 年前

    在这里工作的一些开发人员问我,到目前为止我得到的是:

    “以前从未见过,我甚至从未在Crystal中使用过export to stream选项。但是,如果我猜的话,我会把服务器权限看作一个可能的错误。我见过用户必须具有访问流的特殊权限的情况。”