HttpRequest.IsAuthenticated 屬性

定義

取得值,表示要求是否已經驗證過。

public:
 property bool IsAuthenticated { bool get(); };
public bool IsAuthenticated { get; }
member this.IsAuthenticated : bool
Public ReadOnly Property IsAuthenticated As Boolean

屬性值

Boolean

如果已經驗證要求,則為 true,否則為 false

範例

下列程式碼範例會使用 IsAuthenticated 屬性來判斷目前的要求是否已通過驗證。 如果尚未驗證,要求會重新導向至另一個頁面,讓使用者可以在 Web 應用程式中輸入其認證。 這是應用程式預設頁面中所使用的常見技術。

private void Page_Load(object sender, EventArgs e)
{
    // Check whether the current request has been
    // authenticated. If it has not, redirect the 
    // user to the Login.aspx page.
    if (!Request.IsAuthenticated)
    {
        Response.Redirect("Login.aspx");
    }
}
Private Sub Page_Load(sender As Object, e As EventArgs)
    ' Check whether the current request has been
    ' authenticated. If it has not, redirect the 
    ' user to the Login.aspx page.
    If (Request.IsAuthenticated = False) Then
        Response.Redirect("Login.aspx")
    End If
End Sub

適用於