How to read an ASP.NET internal server error description with .NET?
.net, asp.net, c#, iis, webclient
Solution
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.
Problem
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?