Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read an ASP.NET internal server error description with .NET?

Behold the code:

using (var client = new WebClient())
{
    try
    {
        var bytesReceived = client.UploadData("http://localhost", bytesToPost);
        var response = client.Encoding.GetString(bytesReceived);
    }
    catch (Exception ex)
    {
    }
}

I am getting this HTTP 500 internal server error when the UploadData method is called. But I can't see the error description anywhere in the "ex" object while debugging. How do I rewrite this code so I can read the error description?

like image 842
Jader Dias Avatar asked Jun 18 '09 20:06

Jader Dias


People also ask

How do you solve 500 Internal server error There is a problem with the resource you are looking for and it Cannot be displayed?

500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed. To resolve this issue, set the Enable 32-bit Applications to "False": Open the Internet Information Services (IIS) Manager.

How do I fix internal server error in IIS?

IIS error The error 500.19 is an internal server error often occurring on a server using Microsoft IIS software. It indicates that the configuration data for the page is invalid. To solve the issue, delete the malformed XML element from the Web. config file or from the ApplicationHost.


1 Answers

Web servers often return an error page with more details (either HTML or plain text depending on the server). You can grab this by catching WebException and reading the response stream from its Response property.

like image 51
Christian Hayter Avatar answered Oct 11 '22 03:10

Christian Hayter