HttpRequest.IsAuthenticated 屬性

定義

取得值,表示要求是否已經驗證過。Gets a value indicating whether the request has been authenticated.

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

屬性值

Boolean

如果已經驗證要求,則為 true,否則為 falsetrue if the request is authenticated; otherwise, false.

範例

下列程式碼範例會使用 IsAuthenticated 屬性來判斷目前的要求是否已經過驗證。The following code example uses the IsAuthenticated property to determine whether the current request has been authenticated. 如果未經過驗證,則會將要求重新導向至另一個頁面,讓使用者可以在 Web 應用程式中輸入其認證。If it has not been authenticated, the request is redirected to another page where users can enter their credentials into the Web application. 這是在應用程式的預設頁面中使用的常見技術。This is a common technique used in the default page for an application.

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

適用於