Link to home
Start Free TrialLog in
Avatar of sharizod
sharizodFlag for Canada

asked on

Apache throws: OK The Server encountered an internal error or misconfiguration and was unable to complete your request.

Hi Experts,

I have apache 2.2 server running my asp.net application (using mod_aspdotnet).

My application takes a dataset and generates a dynamic reportviewer object to output a local RDLC report to a comma-delimited file or a PDF file for display in the users browser.  The code to show comma-delimited data in the users browser works but I cannot get the PDF code block to work without Apache throwing back an error as below.  Does anyone have any ideas?  There are no errors in the error log on this one, just the message below.  I do not get any errors when executing this code in the development environment, just when trying to run my app from Apache.

OK
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, x@yz.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

strReportPath &= ".\Reports\" & Session("ReportType") & "\" & sRptSubDirRoot & "\" & sRptName & ".rdlc"


        If Session("Export") = True Then

            Dim sb As New StringBuilder
            With DS.Tables(0)

                For Each col As DataColumn In .Columns
                    sb.Append(col.ColumnName)
                    If col.ColumnName <> .Columns(.Columns.Count - 1).ColumnName Then
                        sb.Append(",")
                    End If
                Next
                For Each dr As DataRow In .Rows
                    sb.Append(vbCrLf)
                    For Each col As DataColumn In .Columns
                        sb.Append(dr.Item(col.ColumnName))
                        If col.ColumnName <> .Columns(.Columns.Count - 1).ColumnName Then
                            sb.Append(",")
                        End If
                    Next
                Next


            End With

            Session("Export") = False

            Response.Clear()
            Response.Buffer = True
            Response.ContentType = "text/plain"
            Response.AddHeader("Content-Disposition", "inline;filename=/cdf.csv")
            Me.EnableViewState = False
            Response.Write(sb.ToString())
            Response.End()



        Else

            If Not IO.File.Exists(MapPath(strReportPath)) Then
                Throw (New Exception("Unable to locate report file:" & _
                  vbCrLf & strReportPath))
            End If

            Dim warnings As Warning() = Nothing
            Dim streamids As String() = Nothing
            Dim mimeType As String = Nothing
            Dim encoding As String = Nothing
            Dim extension As String = Nothing
            Dim bytes As Byte()

            Dim filepath As String = MapPath(".\reports\cache\" & Session("CustomerID") & ".PDF")

            Dim datasource As New ReportDataSource("ds" & sRptName & "_dt" & sRptName, DS.Tables("ds" & sRptName))

            Dim rpv As New ReportViewer()
            rpv.LocalReport.DataSources.Clear()
            rpv.LocalReport.ReportPath = MapPath(strReportPath) 
            rpv.LocalReport.DataSources.Add(datasource)

            bytes = rpv.LocalReport.Render("PDF", Nothing, mimeType, encoding, extension, streamids, _
             warnings)

            If System.IO.File.Exists(filepath) Then
                System.IO.File.Delete(filepath)
            End If

            Dim fs As New System.IO.FileStream(filepath, System.IO.FileMode.Create)
            fs.Write(bytes, 0, bytes.Length)
            fs.Close()

            Response.ContentType = "Application/pdf"
            Response.WriteFile(filepath)
            Response.End()

        End If

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Jayachandran Palanisamy
Jayachandran Palanisamy
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think following line may be the problem

Dim fs As New System.IO.FileStream(filepath, System.IO.FileMode.Create)

If you comment out this line and lines after it, does the error go away?
Avatar of sharizod

ASKER

Hi ChandranJoy,

Should I check for anything specific in the apache conf files?  Also, when you talk of permissions, I am assuming that you mean windows permissions or are you talking about the asp.net application permissions?

CodeCruiser,  remming out the filestream line did not work.  It still gave me the same error message.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Turns out it was point #1 I had to look at again.  Thanks ChandranJoy.
Am not sure why the snippet didn't get attached but here is the code snippet that finally worked!
           
 
Response.Clear()
            Response.ContentType = "application/x-pdf"
            Response.AddHeader("content-disposition", "inline; filename=/Reports/Cache/" & Session("CustomerID") & ".PDF")
            Response.BinaryWrite(bytes)
            Response.End()

Open in new window

Thank you sharizod.

Jay