FormsAuthentication 加密/解密

FormsAuthentication encrypt / decrypt

我有 2 个应用程序,一个名为 www.domain.dk 和一个 m.domain.dk

它们都有登录功能(相同),但是如果你在m.domain.dk上登录然后去www.domain.dk那么它需要记住你已经登录了。

问题来了..

www报错说无法验证m站点设置的cookie中的数据,于是开始调试代码,发现www在加密FormsAuthenticationTicket时,加密后的字符串是64个字符比 m 站点做的时间长。

web.config 中的以下部分对于两个项目都是相同的

<machineKey validationKey="CF3D..." decryptionKey="A56..." validation="SHA1" decryption="AES" />

<authentication mode="Forms">
  <forms name=".ASPXAUTH" domain=".domain.dk" timeout="20" enableCrossAppRedirects="true" path="/" protection="All" cookieless="UseCookies" />
</authentication>

以下代码来自登录函数

var ticket = new FormsAuthenticationTicket(1, user.UserName, DateTime.Now, DateTime.Now.AddMinutes(20), false, string.Empty, "/");
var hashCookies = FormsAuthentication.Encrypt(ticket);

www 是一个旧站点,所以我的问题主要是,除了我 web.config 中的那些之外,还有其他任何可以影响 "FormsAuthentication.Encrypt" 的东西吗?

解决方案是添加

compatibilityMode="Framework20SP1"

到 MachineKey 标签