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 PostAuthenticateRequest事件HttpApplication實例的事件處理常式中設定屬性。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

備註

只有中IIS 7.0IIS 7.0的整合式管線模式才支援屬性,而且至少.NETFramework版本3.0。SubStatusCodeThe 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如果已設定失敗要求追蹤,則狀態會是 [已登入]。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.

適用於

另請參閱