Name

GetHttpCode

Synopsis

integer = HttpException.GetHttpCode(  )

Returns an integer containing the HTTP status code contained within the exception. For most exceptions thrown by the ASP.NET intrinsic objects, this integer will be 500, indicating an HTTP server error.

Parameters

integer

An integer variable to receive the HTTP code from the method.

Example

The code example causes an exception by calling Server.Execute on a page that does not exist. The exception is then caught and the HTTP status code is displayed by calling GetHttpCode:

Sub Page_Load(  )
   Try
      Server.Execute("Foo.aspx")
   Catch HttpEx As HttpException
      Message.Text = "ERROR:<br/>"
      Message.Text &= "Http Status Code: " & _
         HttpEx.GetHttpCode(  ) & "<br/>"
   End Try
End Sub

Notes

This method is most useful for custom exceptions raised in methods that make HTTP calls, since it allows you to pass back the HTTP result code (404 for not found, 403 for access denied, etc.) to the calling client.

Get ASP.NET in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.