在两个MVC项目之间共享.AspNet.ApplicationCookie

时间:2017-06-16 03:51:14

标签: asp.net-mvc redirect cookies

我有一个Web项目来登录我们的用户。它签署用户,创建“.AspNet.ApplicationCookie”cookie,然后重定向到页面“〜/ Views /../ Redirect.cshtml”,根据一些规则,将选择网站用户将是什么重定向到。非常简单,“重定向...”消息和setTimeout函数。

问题是......网站2无法识别网站1创建的cookie,只是将用户移回网站1.

一些信息: 1 - 在本地运行两个站点 2 - 站点1和站点2位于同一域中运行的同一服务器上,只是不同的端口。 3 - 自从我将此类移动到Domain项目后,两个站点共享相同的ApplicationUserManager.Create调用。

Startup.cs如下:

public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context, user manager and signin manager to use a single instance per request
            app.CreatePerOwinContext(AccountDbContext.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("/Account/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, DefaultAuthenticationTypes.ApplicationCookie))
                }
            });
            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 个答案:

答案 0 :(得分:0)

事实证明问题是应用程序池。共享相同cookie的所有站点都需要在同一个应用程序池上运行。一旦我将它们全部设置为使用它,它就可以正常工作。