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.

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
                    If col.ColumnName <> .Columns(.Columns.Count - 1).ColumnName Then
                    End If
                For Each dr As DataRow In .Rows
                    For Each col As DataColumn In .Columns
                        If col.ColumnName <> .Columns(.Columns.Count - 1).ColumnName Then
                        End If

            End With

            Session("Export") = False

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


            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.ReportPath = MapPath(strReportPath) 

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

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

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

            Response.ContentType = "Application/pdf"

        End If

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jayachandran PalanisamyTechnical Consultant - LinuxCommented:
1.Verify your asp.net code part
2.Check the apache configuration (have changed apache config recently?)
3.Ensure the permissions/ownership of the asp.net files/folders

Good luck :)


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day 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?
sharizodAuthor Commented:
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.
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

sharizodAuthor Commented:
Hi guys.

I have an update.  I thought that it might have been permissions as suggested but ruled that out after verifying that the files were being written to the cache folder under the reports root folder.  

I did some more searching and found a post with an issue similar to my own.  The problem seems to be in the setting of the ContentType property.  Apache does not like application/pdf when streaming for some reason but prefers application/x-pdf instead.  So, I changed my htphandler to output to that type instead and it worked!  Final code block replaced is below.   Thanks for the suggestions though!

sharizodAuthor Commented:
Turns out it was point #1 I had to look at again.  Thanks ChandranJoy.
sharizodAuthor Commented:
Am not sure why the snippet didn't get attached but here is the code snippet that finally worked!
            Response.ContentType = "application/x-pdf"
            Response.AddHeader("content-disposition", "inline; filename=/Reports/Cache/" & Session("CustomerID") & ".PDF")

Open in new window

Jayachandran PalanisamyTechnical Consultant - LinuxCommented:
Thank you sharizod.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.