HttpResponse.SubStatusCode 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定一個值,以限定回應的狀態碼。
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 。 把程式碼檔案放進你網頁應用程式的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 中的「使用失敗請求追蹤故障排除失敗請求」。