私のアプリにはクッキー処理が必要です(サインイン/アウト時にセッション変数を更新してください)。すべてが動作しないことASP.NETコア:カスタムクッキー処理
public void Configure(IApplicationBuilder app)
{
//omitted
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
Events = new CookieAuthenticationEvents
{
OnSigningIn = app.ApplicationServices
.GetRequiredService<MyService>().DoSomething
}
});
app.UseIdentity();
//omitted
}
:documentationは、私はこのようなパイプラインにクッキーのミドルウェアを追加した通り
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
}
:まず、私はいくつかのアイデンティティの設定を持っています。 DoSomething
は呼び出されません。私はConfigureServices
にラムダを記述する場合、それは動作します:
i.Cookies.ApplicationCookie.Events = new CookieAuthenticationEvents
{
OnSigningIn = async context => { await Task.FromResult(1); }
};
そこで質問(実際には2本)。 ConfigureServices
方法でサービスをリクエストするにはどうすればいいですか、またはUseCookieAuthentication
のイベントをどのように機能させるのですか?すぐにコールバックを要求する(すべてのサービスが設定されているとき、それは後で呼ばれます)とコールバックはHttpContext
私はHttpContext.RequestServices.GetRequiredService<Type>()
をすることができる静的メソッドを宣言することができますアクセスすることができ、それを通してBasePrincipalContext
を受け入れる場合のよう