HttpResponse.SubStatusCode 屬性

定義

取得或設定的值會評估回應的狀態碼是否合格。

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.0 子狀態碼。

例外狀況

此作業需要 IIS 7.0 中的整合式管線模式,以及至少.NET Framework 3.0 版。

狀態碼是在送出所有 HTTP 標頭之後設定。

範例

下列範例會 SubStatusCode 設定 HttpApplication 事件實例 PostAuthenticateRequest 之事件處理常式中的 屬性。 將程式碼檔案放在 Web 應用程式的 App_Code 資料夾中,並設定 Web.config 檔案來註冊模組。 如需詳細資訊,請參閱 逐步解說:建立和註冊自訂 HTTP 模組

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.0 中的整合式管線模式和至少.NET Framework 3.0 版才支援 屬性。 當您設定 屬性時 SubStatusCode ,如果設定失敗要求追蹤,狀態會記錄在 IIS 7.0。 與是否已設定追蹤無關,程式碼永遠不會傳送為要求最終回應的一部分。 如需詳細資訊,請參閱 使用 IIS 7.0 中的失敗要求追蹤對失敗的要求進行疑難排解

適用於

另請參閱