IIS7 Response.WriteBuffer 不工作

发布于 2024-07-14 18:29:11 字数 3413 浏览 5 评论 0原文

我们有一个 ASP.NET 1.1 应用程序,它使用 Crystal Reports 生成 Excel 电子表格。 这些代码在 IIS6 下运行,但当我们尝试将其迁移到 IIS7 时,它会输出没有内容的 html,而不是 Excel 文件。

MIME 类型存在。 下面是我们正在使用的代码。 我没有编写这段代码,因为我现在主要在 3.5 框架中工作。 我的假设是我缺少 IIS7 配置中的某些内容而不是代码,因为它可以在 IIS6 上运行。 ASP.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()

We have an ASP.NET 1.1 application that uses Crystal Reports to spit out an excel spreadsheet. The codes works under IIS6 but when we try to migrate it to IIS7 it is spitting out html with no content instead of the Excel file.

The MIME Type exists. Below is the code we are using. I did not write this code as I'm working primarily in 3.5 framework now. My assumption is I am missing something in the IIS7 configuration not the code since it works on IIS6. The rest of the ASP.NET 1.1 application works on 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()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

氛圍 2024-07-21 18:29:11

在工作中询问了一些开发人员,这是我到目前为止得到的信息:

“以前从未见过,我什至以前从未在 crystal 中使用过导出到流选项。但是,如果我猜的话,我会查看服务器权限作为一个可能的错误,我见过用户必须具有特殊权限才能访问流的情况。”

Asked some devs here at work, this is what I got so far:

"Never seen that before, I’ve never even used the export to stream option in crystal before. However, if I were to guess, I would look at server permissions as a possible fault. I’ve seen situations where the user has to have special privileges to access streams."

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文