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

适用于