Ich brauche einige Cookie-Verarbeitung in meiner App (Update Sitzungsvariable beim Anmelden/Abmelden). Zuerst habe ich einige Identität config:ASP.NET Core: benutzerdefinierte Cookie-Verarbeitung
public void ConfigureServices(IServiceCollection services)
{
//omitted
services.AddIdentity<ApplicationUser, IdentityRole>(i =>
{
i.Lockout = new LockoutOptions()
{
DefaultLockoutTimeSpan = TimeSpan.FromMinutes(1),
MaxFailedAccessAttempts = 5
};
i.Password.RequireDigit = true;
i.Password.RequireLowercase = true;
})
//omitted
}
Wie die documentation schlagen I Cookie-Middleware in die Pipeline wie folgt hinzugefügt:
public void Configure(IApplicationBuilder app)
{
//omitted
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
Events = new CookieAuthenticationEvents
{
OnSigningIn = app.ApplicationServices
.GetRequiredService<MyService>().DoSomething
}
});
app.UseIdentity();
//omitted
}
Das alles funktioniert nicht. DoSomething
wird nicht aufgerufen. Wenn ich einen Lambda in ConfigureServices
schreiben funktioniert es:
i.Cookies.ApplicationCookie.Events = new CookieAuthenticationEvents
{
OnSigningIn = async context => { await Task.FromResult(1); }
};
Also die Frage (eigentlich zwei). Wie kann ich einen Service in der ConfigureServices
Methode anfordern oder wie die Ereignisse im UseCookieAuthentication
funktionieren?