HttpResponse.SubStatusCode Property

Definition

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

public int SubStatusCode { get; set; }

Property Value

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

Exceptions

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

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

Examples

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.

using System;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;

// Module that sets Response.SubStatusCode in PostAuthenticateRequest event handler.
namespace Samples
{
    public class ModuleExampleTestCS : IHttpModule
    {
        public ModuleExampleTestCS()
        {
            // Constructor
        }
        public void Init(HttpApplication app)
        {
            app.PostAuthenticateRequest += new EventHandler(PostAuthenticateRequest_Handler);
        }
        public void Dispose()
        {
        }
        public void PostAuthenticateRequest_Handler(object source, EventArgs e)
        {
            HttpApplication app = (HttpApplication)source;
            HttpContext context = app.Context;

            // Set a SubStatusCode for Failed Request Tracing in IIS7
            context.Response.SubStatusCode = 99;
        }
    }
}

Remarks

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.

Applies to

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also