2014-02-13 53 views
0

我一直在試圖讓下面的場景在一個星期左右的時間裏工作,但沒有運氣。我有兩個應用程序,一個是支持聲明的.NET 4.5應用程序,可以很好地工作(可與其他.NET 4及更高版本的應用程序一起使用);以及使用WebForms .NET 3.5構建的傳統Intranet系統。遺留的應用程序不能升級到更高版本的.NET(會更容易)。無法解密從.NET 4.5到.NET 3.5的聲明cookie

我想要發生的是,當我登錄.NET 4.5應用程序時,我需要在訪問.NET 3.5應用程序時進行身份驗證。我已確保應用程序之間的Cookie名稱相同,並且web.config中的machineKey值相同(即使在Web Farm場景中,我也使用MachineKeySessionSecurityTokenHandler確保encyrpted cookie值相同);然而,什麼情況是,當我移動到.NET 3.5應用程序,我從SymmetricEncryptionFormatter類出現以下錯誤:

ID0006:輸入字符串參數爲null或empty.Parameter名:價值

我嘗試將MachineKey密鑰(解密密鑰/驗證密鑰/驗證/解密)更改爲各種不同的組合(以確保它們在兩個站點之間一致)。我可以看到,當我訪問這兩個網站時,具有相同cookie值的相同cookie也是可見的。我認爲這個問題可能與.NET 3.5中的Crytographic變化有關。NET 3.5 4.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" /> 

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

重點項目從.NET 3.5應用程序的Web.config:

<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> 

回答

1

內部WIF和.NET 4.5之間的cookie格式已經改變。你不能在版本之間分享它們。

將兩個應用程序指向相同的STS,並讓每個應用程序使用自己的會話cookie。