C#, stop http server errors from throwing exceptions
Posted on 2011-02-14
How do I stop exceptions like this from being thrown?
System.Net.WebException: The remote server returned an error: (405) Method Not Allowed.
I assume it will throw an exception for all sorts of other http errors (404, 500, etc...). I don't want my program to do this. I would like it to get a page just like you would see in a web browser where it shows you the error as HTML and has the stats in the header.
The only way I can think to do this would to put a more specialized web exception catch in front of the general exception catch and ignore them or generate some special flag variable to use later. I'm unsure of how this would affect other errors that may happen though.. So I'm hesitant to do this. What I really want is something like "Request.ReturnHttpStatusException = false;". I think that's wishful thinking though.
Thanks for any help.