FormsAuthenticationModule Klass
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Anger användarens identitet för ett ASP.NET program när formulärautentisering är aktiverat. Det går inte att ärva den här klassen.
public ref class FormsAuthenticationModule sealed : System::Web::IHttpModule
public sealed class FormsAuthenticationModule : System.Web.IHttpModule
type FormsAuthenticationModule = class
interface IHttpModule
Public NotInheritable Class FormsAuthenticationModule
Implements IHttpModule
- Arv
-
FormsAuthenticationModule
- Implementeringar
Exempel
I följande exempel används händelsen FormsAuthentication_OnAuthenticate för att ange User egenskapen för den aktuella HttpContext till ett anpassat IPrincipal objekt.
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
Kommentarer
FormsAuthenticationModule anger den aktuella egenskapen HttpContext.User till ett IPrincipal-objekt som representerar användaridentiteten för den aktuella begäran när autentiseringen Mode är inställt på Forms i elementet authentication Element (ASP.NET Settings Schema) i programmets konfigurationsfil.
FormsAuthenticationModule Exponerar en Authenticate händelse som gör att du kan ange ett anpassat IPrincipal objekt för egenskapen för User den aktuella HttpContext. Händelsen Authenticate nås genom att ange en underrutin med namnet FormsAuthentication_OnAuthenticate i filen Global.asax för ditt ASP.NET-program.
Note
I IIS 7.0 stöds inte användning av WindowsAuthenticationModule med FormsAuthenticationModule . Mer information om kompatibilitetsproblem i integrerade lägen finns i Moving an ASP.NET Application from IIS 6.0 to IIS 7.0.
Konstruktorer
| Name | Description |
|---|---|
| FormsAuthenticationModule() |
Initierar en ny instans av FormsAuthenticationModule klassen. |
Metoder
| Name | Description |
|---|---|
| Dispose() |
Släpper alla resurser, förutom minne, som används av FormsAuthenticationModule. |
| Equals(Object) |
Avgör om det angivna objektet är lika med det aktuella objektet. (Ärvd från Object) |
| GetHashCode() |
Fungerar som standard-hash-funktion. (Ärvd från Object) |
| GetType() |
Hämtar den aktuella instansen Type . (Ärvd från Object) |
| Init(HttpApplication) |
Initierar FormsAuthenticationModule-objektet. |
| MemberwiseClone() |
Skapar en ytlig kopia av den aktuella Object. (Ärvd från Object) |
| ToString() |
Returnerar en sträng som representerar det aktuella objektet. (Ärvd från Object) |
Händelser
| Name | Description |
|---|---|
| Authenticate |
Inträffar när programmet autentiserar den aktuella begäran. |