WebException.Status Property
.NET Framework 4
Gets the status of the response.
Assembly: System (in System.dll)
The Status property indicates the reason for the WebException.
The value of Status is one of the WebExceptionStatus values.
The following example checks the Status property and prints to the console the StatusCode and StatusDescription of the underlying HttpWebResponse instance.
try { // Create a web request for an invalid site. Substitute the "invalid site" strong in the Create call with a invalid name. HttpWebRequest myHttpWebRequest = (HttpWebRequest) WebRequest.Create("invalid site"); // Get the associated response for the above request. HttpWebResponse myHttpWebResponse = (HttpWebResponse) myHttpWebRequest.GetResponse(); myHttpWebResponse.Close(); } catch(WebException e) { Console.WriteLine("This program is expected to throw WebException on successful run."+ "\n\nException Message :" + e.Message); if(e.Status == WebExceptionStatus.ProtocolError) { Console.WriteLine("Status Code : {0}", ((HttpWebResponse)e.Response).StatusCode); Console.WriteLine("Status Description : {0}", ((HttpWebResponse)e.Response).StatusDescription); } } catch(Exception e) { Console.WriteLine(e.Message); }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.