2016-07-04 47 views
0

我使用SignalR 2.2.0和MVC 4。當我打開我的Chrome瀏覽器網頁,我收到一個錯誤在控制檯:SignalR - 指定的解密密鑰無效的十六進制字符

http://localhost:8180/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22chathub%22%7D%5D&_=1467627883530 500 (Internal Server Error) 

經進一步檢查使用菲德勒我可以查看堆棧跟蹤:

[ConfigurationErrorsException]: Decryption key specified has invalid hex characters. (C:\Users\Foo\web.config line 66) 

    at System.Web.Security.Cryptography.MachineKeyMasterKeyProvider.GenerateCryptographicKey(String configAttributeName, String configAttributeValue, Int32 autogenKeyOffset, Int32 autogenKeyCount, String errorResourceString) 
    at System.Web.Security.Cryptography.MachineKeyMasterKeyProvider.GetEncryptionKey() 
    at System.Web.Security.Cryptography.Purpose.GetDerivedEncryptionKey(IMasterKeyProvider masterKeyProvider, KeyDerivationFunction keyDerivationFunction) 
    at System.Web.Security.Cryptography.AspNetCryptoServiceProvider.GetNetFXCryptoService(Purpose purpose, CryptoServiceOptions options) 
    at System.Web.Security.Cryptography.AspNetCryptoServiceProvider.GetCryptoService(Purpose purpose, CryptoServiceOptions options) 
    at System.Web.Security.MachineKey.Protect(ICryptoServiceProvider cryptoServiceProvider, Byte[] userData, String[] purposes) 
    at System.Web.Security.MachineKey.Protect(Byte[] userData, String[] purposes) 
    at Microsoft.Owin.Host.SystemWeb.DataProtection.MachineKeyDataProtector.Protect(Byte[] userData) 
    at Microsoft.Owin.Security.DataProtection.AppBuilderExtensions.CallDataProtectionProvider.CallDataProtection.Protect(Byte[] userData) 
    at Microsoft.AspNet.SignalR.Infrastructure.DataProtectionProviderProtectedData.Protect(String data, String purpose) 
    at Microsoft.AspNet.SignalR.PersistentConnection.ProcessNegotiationRequest(HostContext context) 
    at Microsoft.AspNet.SignalR.PersistentConnection.ProcessRequest(HostContext context) 
    at Microsoft.AspNet.SignalR.Hubs.HubDispatcher.ProcessRequest(HostContext context) 
    at Microsoft.AspNet.SignalR.PersistentConnection.ProcessRequest(IDictionary`2 environment) 
    at Microsoft.AspNet.SignalR.Owin.Middleware.HubDispatcherMiddleware.Invoke(IOwinContext context) 
    at Microsoft.Owin.Infrastructure.OwinMiddlewareTransition.Invoke(IDictionary`2 environment) 
    at Microsoft.Owin.Mapping.MapMiddleware.<Invoke>d__0.MoveNext() 

從我收集的,SignalR使用機器的關鍵部分進行加密/解密。

這是機器的關鍵看起來像什麼:

<machineKey decryptionKey="5E329ED7DE2786FCD906E717C97A09BE26B3564BBE0A2B28,IsolateApps" validationKey="A64F709FB47B282CB8331205BC423D63450B4FFC92FE06EC1E00B3AE8B5B1F529A5CD1064F66C08545FC13B013F84153598B29213D5494DD5EC348B537A51DAE,IsolateApps"/> 

我猜它看到「IsolateApps」在decryptionKey /的validationKey和拋出異常(「...無效的十六進制字符」)。

如果我從密鑰中刪除「IsolateApps」,我無法再登錄,因爲我使用的是FormsAuthentication,後者又使用密鑰來加密/解密。因此,刪除「IsolateApps」似乎不是一個解決方案。

PS。我使用的代碼是this教程。 我已經看過this answer但它不能解決問題。我也嘗試將compatibilityMode="Framework20SP1"添加到機器密鑰中,但這也不起作用。

有沒有辦法解決這個問題,而無需從網絡配置中的鍵刪除「IsolateApps」值?

回答

1

我已經解決了這個問題。我決定刪除該停止給該異常的機鍵「,IsolateApps」屬性:

Decryption key specified has invalid hex characters

刪除此屬性意味着我無法登錄了(因爲機器密鑰技術上改變),這迫使我重新設置我的帳戶密碼。有一次,我重置密碼,我可以記錄繼續

一旦我能登錄,我收到此錯誤:

ws://xxxxx/signalr/connect?transport=webSockets&clientProtocol=1.5&connectionToken=xxxxx' failed: Connection closed before receiving a handshake response.

此異常只被在Chrome中拋出。

由於web套接字握手不成功,SignalR回退到服務器發送的事件。幾個小時的調試後,我加入這web配置解決了這個問題:

<system.web> 
    <compilation debug="true" targetFramework="4.5" /> 
    <httpRuntime targetFramework="4.5" /> 
    <pages controlRenderingCompatibilityVersion="4.0" /> 
</system.web> 

一旦加入,SignalR被用作除外。

+0

刪除IsolateApps爲我工作,所以謝謝。不過,在進行配置更改後,我仍然回落到SSE。 :( –

相關問題