HttpResponse.SubStatusCode Property

 

Gets or sets a value qualifying the status code of the response.

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

Public Property SubStatusCode As Integer

Property Value

Type: System.Int32

An integer value that represents the IIS 7.0 sub status code.

Exception Condition
PlatformNotSupportedException

The operation requires the integrated pipeline mode in IIS 7.0 and at least the .NET Framework version 3.0.

HttpException

The status code is set after all HTTP headers have been sent.

The SubStatusCode property is only supported with the integrated pipeline mode in IIS 7.0 and at least the .NET Framework version 3.0. When you set the SubStatusCode property, the status is logged on IIS 7.0 if failed-request tracing is configured. Independent of whether tracing is configured, the code is never sent as part of the final response to the request. For more information, see Troubleshooting Failed Requests Using Failed Request Tracing in IIS 7.0.

The following example sets the SubStatusCode property in an event handler for the HttpApplication instance of the PostAuthenticateRequest event. Put the code file in the App_Code folder of your Web application and configure the Web.config file to register the module. For more information, see Walkthrough: Creating and Registering a Custom HTTP Module.

Imports System
Imports System.Data
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports Microsoft.VisualBasic

' Module that sets Response.SubStatusCode in PostAuthenticateRequest event handler.
Namespace Samples

    Public Class ModuleExampleTestVB
        Implements IHttpModule

        Public Sub New()
            ' Constructor
        End Sub

        Public Sub Init(ByVal app As HttpApplication) Implements IHttpModule.Init
            AddHandler app.PostAuthenticateRequest, AddressOf Me.PostAuthenticateRequest_Handler
        End Sub

        Public Sub Dispose() Implements IHttpModule.Dispose
        End Sub

        Public Sub PostAuthenticateRequest_Handler(ByVal source As Object, ByVal e As EventArgs)
            Dim app As HttpApplication = CType(source, HttpApplication)
            Dim context As HttpContext = app.Context

            ' Set a SubStatusCode for Failed Request Tracing in IIS7.
            context.Response.SubStatusCode = 99
        End Sub
    End Class

End Namespace

.NET Framework
Available since 2.0
Return to top
Show: