MVC 5 + ASP身份授权 - 在子域中共享cookie

时间:2015-11-05 09:27:47

标签: cookies asp.net-mvc-5 subdomain asp.net-identity

我的本​​地网站包含以下子域名:

localhost:55307
aaa.localhost:55307
bbb.localhost:55307

除了授权外它完美无缺 - 如果我登录localhost:55307我没有登录aaa.localhost:55307,因为我的子域名被视为单独的域名。我正在寻找解决方案,但我找不到任何Asp Identity(MVC 4中的表单身份验证它没用)。 基于SO中的一些问题和答案我做了:

  1. CookieAuthenticationOptions中修改Startup.Auth.cs课程,如下所示:

    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
    LoginPath = new PathString("/Account/Login"),
    CookieDomain = ".localhost",
    ExpireTimeSpan = new TimeSpan(0,12,0,0,0),
    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))
    }
    
  2. 从IIS管理器获取MachineKey并添加到web.config:

  3. <system.web> <authentication mode="None" /> <machineKey validationKey="61D42DE996486DEA64CEA26C0373C547E0D07108789662C2D2E15210A65C475925055009D962FEB3D5D93E9BEA3E3717187F1BCBF63E386EB198F641E6157044" decryptionKey="06CF7C1C31BDBD4E7056D0F3531BE253E98A658B50974155" validation="SHA1" decryption="Auto"/> <compilation debug="true" targetFramework="4.5.2" /> <httpRuntime targetFramework="4.5.2" maxRequestLength="1073741824" /> </system.web>

    现在我可以登录但不共享cookie - 我仍然登录了一个子域。

    PS。我现在在StackOberflow中有很多类似的问题,但其中没有一个是关于MVC 5和ASP Identity的,并且他们没有得到解决方案。

0 个答案:

没有答案
相关问题