Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法将声明cookie从.NET 4.5解密到.NET 3.5_C#_.net_.net 3.5_.net 4.5_Claims Based Identity - Fatal编程技术网

C# 无法将声明cookie从.NET 4.5解密到.NET 3.5

C# 无法将声明cookie从.NET 4.5解密到.NET 3.5,c#,.net,.net-3.5,.net-4.5,claims-based-identity,C#,.net,.net 3.5,.net 4.5,Claims Based Identity,我已经试着让下面的场景工作了大约一个星期,现在没有运气。我有两个应用程序,一个支持声明的.NET4.5应用程序,运行良好(与其他.NET4及以上应用程序配合使用);以及使用WebForms.NET3.5构建的传统Intranet系统。旧版应用程序无法升级到更高版本的.NET(这会容易得多) 我想做的是,当我登录.NET4.5应用程序时,我需要在访问.NET3.5应用程序时进行身份验证。我已确保应用程序之间的Cookie名称相同,并且web.config中的machineKey值相同(我使用Mac

我已经试着让下面的场景工作了大约一个星期,现在没有运气。我有两个应用程序,一个支持声明的.NET4.5应用程序,运行良好(与其他.NET4及以上应用程序配合使用);以及使用WebForms.NET3.5构建的传统Intranet系统。旧版应用程序无法升级到更高版本的.NET(这会容易得多)

我想做的是,当我登录.NET4.5应用程序时,我需要在访问.NET3.5应用程序时进行身份验证。我已确保应用程序之间的Cookie名称相同,并且web.config中的machineKey值相同(我使用MachineKeySessionSecurityTokenHandler确保即使在web场场景中,加密的Cookie值也相同);但是,当我移动到.NET 3.5应用程序时,SymmetricEncryptionFormatter类会出现以下错误:

ID0006:输入字符串参数为null或空。参数名称:value

我尝试将MachineKey密钥(decryptionkey/validationkey/validation/decryptiom)更改为各种不同的组合(确保它们在两个站点之间保持一致)。当我进入这两个站点时,我可以看到相同的cookie,具有相同的cookie值。我认为这个问题可能与.NET3.5和.NET4.5之间的晶体结构变化有关(参见此处)[http://blogs.msdn.com/b/webdev/archive/2012/10/23/cryptographic-improvements-in-asp-net-4-5-pt-2.aspx])

有没有人知道是什么原因造成的

来自.NET 4.5应用程序Web.config的关键条目:

<system.identityModel>
<identityConfiguration>
<securityTokenHandlers>
<remove type="System.IdentityModel.Tokens.SessionSecurityTokenHandler, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<add type="System.IdentityModel.Services.Tokens.MachineKeySessionSecurityTokenHandler, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />  
</securityTokenHandlers>
</identityConfiguration>
</system.identityModel>

<authentication mode="None" />
<authentication mode="None"/>

<machineKey decryptionKey="CC510DF4..." validationKey="BEAC835EEC..." />

<microsoft.identityModel>
<service>
  <securityTokenHandlers>
    <!-- Replace the SessionSecurityTokenHandler with our own. -->
    <remove type="Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    <add type="MachineKeySessionSecurityTokenHandler, App_Code"/>
  </securityTokenHandlers>
</service>
</microsoft.identityModel>

<microsoft.identityModel.services>
<federationConfiguration>
<wsFederation passiveRedirectEnabled="true" issuer="http://localhost:51318/" realm="http://localhost:57083/" requireHttps="false"/>
<cookieHandler requireSsl="false" name="TestName"/>
</federationConfiguration>
</microsoft.identityModel.services>


来自.NET 3.5应用程序Web.config的关键条目:

<system.identityModel>
<identityConfiguration>
<securityTokenHandlers>
<remove type="System.IdentityModel.Tokens.SessionSecurityTokenHandler, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<add type="System.IdentityModel.Services.Tokens.MachineKeySessionSecurityTokenHandler, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />  
</securityTokenHandlers>
</identityConfiguration>
</system.identityModel>

<authentication mode="None" />
<authentication mode="None"/>

<machineKey decryptionKey="CC510DF4..." validationKey="BEAC835EEC..." />

<microsoft.identityModel>
<service>
  <securityTokenHandlers>
    <!-- Replace the SessionSecurityTokenHandler with our own. -->
    <remove type="Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    <add type="MachineKeySessionSecurityTokenHandler, App_Code"/>
  </securityTokenHandlers>
</service>
</microsoft.identityModel>

<microsoft.identityModel.services>
<federationConfiguration>
<wsFederation passiveRedirectEnabled="true" issuer="http://localhost:51318/" realm="http://localhost:57083/" requireHttps="false"/>
<cookieHandler requireSsl="false" name="TestName"/>
</federationConfiguration>
</microsoft.identityModel.services>

cookie的内部格式在WIF和.NET 4.5之间发生了更改。您不能在版本之间共享它们

而是将两个应用指向相同的STS,让每个应用使用自己的会话cookie