HttpResponse.SubStatusCode 属性

定义

获取或设置一个限定响应的状态代码的值。Gets or sets a value qualifying the status code of the response.

public:
 property int SubStatusCode { int get(); void set(int value); };
public int SubStatusCode { get; set; }
member this.SubStatusCode : int with get, set
Public Property SubStatusCode As Integer

属性值

表示 IIS 7.0IIS 7.0 子状态代码的整数值。An integer value that represents the IIS 7.0IIS 7.0 sub status code.

异常

该操作要求使用 IIS 7.0IIS 7.0 中的集成管道模式,并且 .NET Framework 至少为 3.0 版本。The operation requires the integrated pipeline mode in IIS 7.0IIS 7.0 and at least the .NET Framework version 3.0.

状态代码在发送完所有 HTTP 标头之后设置。The status code is set after all HTTP headers have been sent.

示例

下面的示例在事件SubStatusCode的事件处理程序HttpApplication PostAuthenticateRequest中设置属性。The following example sets the SubStatusCode property in an event handler for the HttpApplication instance of the PostAuthenticateRequest event. 将代码文件放在 Web 应用程序的 App_Code 文件夹中,并配置 Web.config 文件以注册模块。Put the code file in the App_Code folder of your Web application and configure the Web.config file to register the module. 有关详细信息,请参见演练:创建和注册自定义 HTTP 模块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;
        }

    }
}
Imports System.Data
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI

' 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

注解

SubStatusCode属性仅支持中IIS 7.0IIS 7.0的集成管道模式,并且至少支持 .NET Framework 版本3.0。The SubStatusCode property is only supported with the integrated pipeline mode in IIS 7.0IIS 7.0 and at least the .NET Framework version 3.0. 设置SubStatusCode属性时, IIS 7.0IIS 7.0如果配置了 failed-请求跟踪,状态将为 "已登录"。When you set the SubStatusCode property, the status is logged on IIS 7.0IIS 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. 有关详细信息,请参阅IIS 7.0 中的使用失败请求跟踪对失败请求进行故障排除For more information, see Troubleshooting Failed Requests Using Failed Request Tracing in IIS 7.0.

适用于

另请参阅