Asp.net mvc 在从Visual Studio运行的两个项目之间共享MVC 5 Owin应用程序cookie

Asp.net mvc 在从Visual Studio运行的两个项目之间共享MVC 5 Owin应用程序cookie,asp.net-mvc,visual-studio-2015,asp.net-mvc-5,owin,Asp.net Mvc,Visual Studio 2015,Asp.net Mvc 5,Owin,因此,我有一个解决方案,包含两个MVC5 Web应用程序,都使用Owin身份验证。 当我通过Visual Studio 2015同时运行这两个应用程序时,owin上下文是共享的(不应该是共享的!) 通过共享,我的意思是每当我向一个应用程序添加声明时,它也会添加到另一个应用程序。这将导致User.Identity.GetUserId()返回我上次登录的应用程序的UserId,即使这两个应用程序彼此无关,并且彼此之间没有引用 我使用默认的Owin设置: public void Configu

因此,我有一个解决方案,包含两个MVC5 Web应用程序,都使用Owin身份验证。 当我通过Visual Studio 2015同时运行这两个应用程序时,owin上下文是共享的(不应该是共享的!)

通过共享,我的意思是每当我向一个应用程序添加声明时,它也会添加到另一个应用程序。这将导致
User.Identity.GetUserId()
返回我上次登录的应用程序的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);

    }
public void ConfigureAuth(IAppBuilder应用程序)
{
//将数据库上下文、用户管理器和登录管理器配置为每个请求使用一个实例
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext(ApplicationUserManager.Create);
app.CreatePerOwinContext(ApplicationSignInManager.Create);
//使应用程序能够使用cookie存储登录用户的信息
//以及使用cookie临时存储用户登录第三方登录提供商的信息
//配置登录cookie
app.UseCookieAuthentication(新的CookieAuthenticationOptions
{
AuthenticationType=DefaultAuthenticationTypes.ApplicationOkie,
LoginPath=新路径字符串(“/Login”),
Provider=新CookieAuthenticationProvider
{
//允许应用程序在用户登录时验证安全戳。
//这是一种安全功能,在您更改密码或向帐户添加外部登录时使用。
OnValidateIdentity=SecurityStampValidator.OnValidateIdentity(
validateInterval:TimeSpan.FromMinutes(30),
regenerateIdentity:(管理器,用户)=>user.GenerateUserIdentityAsync(管理器))
}
});            
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
//允许应用程序在验证双因素身份验证过程中的第二个因素时临时存储用户信息。
app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie,TimeSpan.FromMinutes(5));
//使应用程序能够记住第二个登录验证因素,如电话或电子邮件。
//选中此选项后,登录过程中的第二步验证将在您登录的设备上被记住。
//这类似于登录时的RememberMe选项。
app.useTowFactoryMemberBrowserCookie(DefaultAuthenticationTypes.TwoFactoryRememberBrowserCookie);
}
有人能帮我配置我的应用程序,使它们不共享应用程序cookie吗?

更改

确定用于持久化标识的cookie名称。默认值为“.AspNet.Cookies”。如果更改AuthenticationType的名称,尤其是如果系统多次使用cookie身份验证中间件,则应更改此值


谢谢。这就是我要找的环境,而且很有效。
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    CookieName = "AspNet.AppName"
}