在同一个域共享两个网站的cookie [英] Sharing a cookie between two websites on the same domain

查看:1053
本文介绍了在同一个域共享两个网站的cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的情况:

  • Website A, ASP.NET MVC 4 web application. Domain: http://a.mysite.com
  • Website B, ASP.NET MVC 4 web applicaiton. Domain: http://b.mysite.com

我想分享一个cookie(窗体身份验证)的网站之间。

I'm trying to share a cookie (forms authentication) between the websites.

我不使用每本身Forms身份验证。我使用的是内置方法(加密,解密等),但我设置我自己的自定义的cookie。

I'm not using Forms Authentication per-se. I'm using the built-in methods (Encrypt, Decrypt, etc), but I'm setting my own custom cookie.

当我设置Cookie的网站之一,其他的人看到了饼干,但不能解密。错误是一个加密操作过程中出现错误全国通用的。

When I set the cookie on one of the websites, the other ones sees the cookie, but can't decrypt it. The error is the generic "Error occurred during a cryptographic operation".

我所保证:


  1. 该cookie设置为mysite.com域(即子域可以访问,证明是其他网站可以看到的cookie)。

  2. 两个网站共享同一台机器密钥。两者的web.config中先后为decryptionKey和validationKey的。
  3. 相同的值
  4. 窗体身份验证票证版和cookie名是通过这两个网站是一样的。

  5. 的路径设置为/。

我以前这样做,它工作正常,但在这种情况下这两个应用程序都共享同一个code基地。

I've done this before and it works fine, but in that scenario both applications were sharing the same code base.

在这种情况下,它们是单独的应用程序。这是因为我是原型设计解决方案,其中在相同的顶级域两个独立平台的应用程序可以共享一个身份验证cookie。

In this instance, they are separate applications. This is because i am prototyping a solution where two platform-independent applications on the same top level domain can share a authentication cookie.

谁能告诉我什么,我缺少的,或者提供替代解决方案。

Can anyone tell me what i's missing, or provide an alternative solution.

我读过的所有相关问题,但得到的答复通常为2)以上。

I've read all the related questions, but the answer is usually 2) above.

推荐答案

当你创建一个新的ASP.NET 4.5(如ASP.NET MVC 4)应用程序,以下行被添加到web.config中:

When you create a new ASP.NET 4.5 (e.g ASP.NET MVC 4) application, the following line is added to the web.config:

<httpRuntime targetFramework="4.5" />

这是不是在我的其他应用程序present,可能是因为我的其他应用是其升级到4.5,ASP.NET 3.5应用程序。

This was not present in my other application, possibly because my other application was an ASP.NET 3.5 application which was upgraded to 4.5.

删除固定问题的新的ASP.NET Web应用程序该行。

Removing that line in the new ASP.NET web application fixed the problem.

我认为这是由于兼容性模式值:
<一href=\"http://msdn.microsoft.com/en-us/library/system.web.configuration.machinekeysection.compatibilitymode.aspx\">http://msdn.microsoft.com/en-us/library/system.web.configuration.machinekeysection.compatibilitymode.aspx

I think this is due to the compatability mode value: http://msdn.microsoft.com/en-us/library/system.web.configuration.machinekeysection.compatibilitymode.aspx

Framework45。加密增强对ASP.NET 4.5已生效。这是默认值,如果应用程序Web.config文件中有设置为4.5的元素的httpRuntime的targetFramework属性。

Framework45. Cryptographic enhancements for ASP.NET 4.5 are in effect. This is the default value if the application Web.config file has the targetFramework attribute of the httpRuntime element set to "4.5".

不知道我是如何得到去除线解决了这个问题。我假设应用程序都有不同的兼容性模式,因为它没有那么的httpRuntime 元素。

Not sure i get how removing that line solved the problem. I assume application one has a different compatability mode, since it didn't have that httpRuntime element.

这篇关于在同一个域共享两个网站的cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆