Login.OnAuthenticate(AuthenticateEventArgs) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
引发 Authenticate 事件以验证用户身份。
protected:
virtual void OnAuthenticate(System::Web::UI::WebControls::AuthenticateEventArgs ^ e);
protected virtual void OnAuthenticate (System.Web.UI.WebControls.AuthenticateEventArgs e);
abstract member OnAuthenticate : System.Web.UI.WebControls.AuthenticateEventArgs -> unit
override this.OnAuthenticate : System.Web.UI.WebControls.AuthenticateEventArgs -> unit
Protected Overridable Sub OnAuthenticate (e As AuthenticateEventArgs)
参数
包含事件数据的 AuthenticateEventArgs。
示例
下面的代码示例使用 Authenticate 事件调用特定于站点的自定义身份验证代码。
<%@ page language="C#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
// This custom login control overloads the OnAuthenticate method
// to call a site-specific authentication method.
class CustomLogin : Login
{
private bool SiteSpecificAuthenticationMethod(string UserName, string Password)
{
// Insert code that implements a site-specific custom
// authentication method here.
//
// This example implementation always returns false.
return false;
}
override protected void OnAuthenticate(AuthenticateEventArgs e)
{
bool Authenticated = false;
Authenticated = SiteSpecificAuthenticationMethod(UserName, Password);
e.Authenticated = Authenticated;
}
}
// Add the custom login control to the page.
void Page_Load(object sender, EventArgs e)
{
CustomLogin loginControl = new CustomLogin();
loginControl.ID = "loginControl";
Placeholder1.Controls.Add(loginControl);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<asp:placeholder id="Placeholder1" runat="server"></asp:placeholder>
</form>
</body>
</html>
<%@ page language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
' This custom login control overloads the OnAuthenticate method
' to call a site-specific authentication method.
Class CustomLogin
Inherits Login
Private Function SiteSpecificAuthenticationMethod(ByVal UserName As String, ByVal Password As String) As Boolean
' Insert code that implements a site-specific custom
' authentication method here.
'
' This example implementation always returns false.
Return False
End Function
Overloads Sub OnAuthenticate(ByVal e As AuthenticateEventArgs)
Dim Authenticated As Boolean
Authenticated = SiteSpecificAuthenticationMethod(UserName, Password)
e.Authenticated = Authenticated
End Sub
End Class
' Add the custom login control to the page.
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim loginControl As New CustomLogin
loginControl.ID = "loginControl"
PlaceHolder1.Controls.Add(loginControl)
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<asp:placeholder id="PlaceHolder1" runat="server"></asp:placeholder>
</form>
</body>
</html>
注解
OnAuthenticate 方法引发 Authenticate 事件。 Authenticate使用 事件实现自定义身份验证方案。
引发事件时,将通过委托调用事件处理程序。 有关详细信息,请参阅 处理和引发事件。
OnAuthenticate 方法还允许派生类对事件进行处理而不必附加委托。 这是在派生类中处理事件的首选技术。
继承者说明
在派生类中重写 OnAuthenticate(AuthenticateEventArgs) 时,一定要调用基类的 OnAuthenticate(AuthenticateEventArgs) 方法,以便已注册的委托对事件进行接收。