2017-01-17 12 views
1

私のアプリにはクッキー処理が必要です(サインイン/アウト時にセッション変数を更新してください)。すべてが動作しないこと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を受け入れる場合のよう

答えて

0

私は要求されたサービスインスタンスを得るために呼ばれる

関連する問題