FormsAuthenticationEventHandler Delegar
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Representa o método que gere o evento FormsAuthentication_OnAuthenticate de um FormsAuthenticationModule.
public delegate void FormsAuthenticationEventHandler(System::Object ^ sender, FormsAuthenticationEventArgs ^ e);
public delegate void FormsAuthenticationEventHandler(object sender, FormsAuthenticationEventArgs e);
type FormsAuthenticationEventHandler = delegate of obj * FormsAuthenticationEventArgs -> unit
Public Delegate Sub FormsAuthenticationEventHandler(sender As Object, e As FormsAuthenticationEventArgs)
Parâmetros
- sender
- Object
A origem do evento.
A FormsAuthenticationEventArgs que contém os dados do evento.
Exemplos
O seguinte exemplo de código usa o evento FormsAuthentication_OnAuthenticate para definir a User propriedade da corrente HttpContext para um GenericPrincipal objeto com um objeto personalizado Identity.
public void FormsAuthentication_OnAuthenticate(object sender, FormsAuthenticationEventArgs args)
{
if (FormsAuthentication.CookiesSupported)
{
if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
{
try
{
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(
Request.Cookies[FormsAuthentication.FormsCookieName].Value);
args.User = new System.Security.Principal.GenericPrincipal(
new Samples.AspNet.Security.MyFormsIdentity(ticket),
new string[0]);
}
catch (Exception e)
{
// Decrypt method failed.
}
}
}
else
{
throw new HttpException("Cookieless Forms Authentication is not " +
"supported for this application.");
}
}
Public Sub FormsAuthentication_OnAuthenticate(sender As Object, _
args As FormsAuthenticationEventArgs)
If FormsAuthentication.CookiesSupported Then
If Not Request.Cookies(FormsAuthentication.FormsCookieName) Is Nothing Then
Try
Dim ticket As FormsAuthenticationTicket = FormsAuthentication.Decrypt( _
Request.Cookies(FormsAuthentication.FormsCookieName).Value)
args.User = New System.Security.Principal.GenericPrincipal( _
New Samples.AspNet.Security.MyFormsIdentity(ticket), _
New String(0) {})
Catch e As HttpException
' Decrypt method failed.
End Try
End If
Else
Throw New Exception("Cookieless Forms Authentication is not " & _
"supported for this application.")
End If
End Sub
Observações
O FormsAuthenticationEventHandler delegado é definido para o Authenticate evento da FormsAuthenticationModule turma. Pode aceder ao evento Authenticate da classe FormsAuthenticationModule especificando uma sub-rotina chamada FormsAuthentication_OnAuthenticate no ficheiro Global.asax da sua aplicação ASP.NET. O Authenticate evento é levantado durante o AuthenticateRequest evento.
O FormsAuthenticationModule objeto constrói FormsAuthenticationEventArgs um objeto usando a corrente HttpContext e passa-o para o evento FormsAuthentication_OnAuthenticate .
Pode usar a User propriedade do FormsAuthenticationEventArgs objeto fornecida ao evento FormsAuthentication_OnAuthenticate para definir a User propriedade do atual HttpContext para um objeto personalizado IPrincipal . Se não especificar um valor para a User propriedade durante o evento FormsAuthentication_OnAuthenticate , a identidade fornecida pelo ticket de autenticação dos formulários no cookie ou URL é utilizada.
O evento FormsAuthentication_OnAuthenticate só é ativado quando a autenticação Mode está definida como Forms e e é FormsAuthenticationModule um módulo HTTP ativo para a aplicação.
Métodos da Extensão
| Name | Description |
|---|---|
| GetMethodInfo(Delegate) |
Obtém um objeto que representa o método representado pelo delegado especificado. |