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

LVL 1
sharizodAsked:
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:
Hi,
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 :)

Jay
0

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
CodeCruiserCommented:
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?
0
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.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

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!

0
sharizodAuthor Commented:
Turns out it was point #1 I had to look at again.  Thanks ChandranJoy.
0
sharizodAuthor Commented:
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

0
Jayachandran PalanisamyTechnical Consultant - LinuxCommented:
Thank you sharizod.

Jay
0
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
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.