2017-01-05 9 views
0

2つのMVC5 Webアプリケーションを使用するソリューションがあり、両方ともOwin認証を使用します。 Visual Studio 2015で両方のアプリケーションを同時に実行すると、owinコンテキストが共有されます(これは共有ではありません)。MVC 5 Owinアプリケーションのクッキーは、Visual Studioから実行される2つのプロジェクト間で共有されます

共有すると、アプリケーションのいずれかにクレームを追加するたびにもう一方にも加えられました。これにより、User.Identity.GetUserId()は、2つのアプリケーションが互いに関係がなく、お互いの間に参照がなくても、最後にログインしたUserIdが返されます。

私はデフォルトOwin設定を使用:

public void ConfigureAuth(IAppBuilder app) 
    { 
     // Configure the db context, user manager and signin manager to use a single instance per request 
     app.CreatePerOwinContext(ApplicationDbContext.Create); 
     app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create); 
     app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create); 

     // Enable the application to use a cookie to store information for the signed in user 
     // and to use a cookie to temporarily store information about a user logging in with a third party login provider 
     // Configure the sign in cookie 
     app.UseCookieAuthentication(new CookieAuthenticationOptions 
     { 
      AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, 
      LoginPath = new PathString("/Login"), 
      Provider = new CookieAuthenticationProvider 
      { 
       // Enables the application to validate the security stamp when the user logs in. 
       // This is a security feature which is used when you change a password or add an external login to your account. 
       OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
        validateInterval: TimeSpan.FromMinutes(30), 
        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)) 
      } 
     });    
     app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); 

     // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process. 
     app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5)); 

     // Enables the application to remember the second login verification factor such as phone or email. 
     // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from. 
     // This is similar to the RememberMe option when you log in. 
     app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie); 

    } 

は、誰かが、彼らはアプリケーションのクッキーを共有しないように、私は、私のアプリを設定助けることができますか?

答えて

1

変更CookieName in CookieAuthenticationOptions

はアイデンティティを永続化するために使用されるCookie名を決定します。デフォルト値は ".AspNet.Cookies"です。この値は、特にシステムがCookie認証ミドルウェアを複数回使用する場合は、AuthenticationTypeの名前を変更する場合に変更する必要があります。

app.UseCookieAuthentication(new CookieAuthenticationOptions 
{ 
    CookieName = "AspNet.AppName" 
} 
+0

ありがとうございます。それは私が探していた設定だったし、それは機能します。 – MichaelCleverly

関連する問題