WebException.Status Property

 

Gets the status of the response.

Namespace:   System.Net
Assembly:  System (in System.dll)

Public ReadOnly Property Status As WebExceptionStatus

Property Value

Type: System.Net.WebExceptionStatus

One of the WebExceptionStatus values.

The Status property indicates the reason for the WebException.

The value of Status is one of the WebExceptionStatus values.

System_CAPS_warningWarning

The ProxyNameResolutionFailure error is not returned to Windows 8.x Store apps.

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.
     Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create("invalid site"), HttpWebRequest)

     'Get the associated response for the above request.
     Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
     myHttpWebResponse.Close()
 Catch e As WebException
     Console.WriteLine(e.Message)

      If e.Status = WebExceptionStatus.ProtocolError Then
         Console.WriteLine("Status Code : {0}", CType(e.Response, HttpWebResponse).StatusCode)
         Console.WriteLine("Status Description : {0}", CType(e.Response, HttpWebResponse).StatusDescription)
     End If

Catch e As Exception
     Console.WriteLine(e.Message)
 End Try

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show: