我在部署在Azure WebSites中的SignalR中遇到了这个异常。它在调试环境中工作得很好。它是SignalR 1.0.1,我使用的是.NET MVC和WebApi
The data protection operation was unsuccessful. This may have been caused by not having the user profile loaded for the current thread's user context, which may be the case when the thread is impersonating.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Security.Cryptography.CryptographicException: The data protection operation was unsuccessful. This may have been caused by not having the user profile loaded for the current thread's user context, which may be the case when the thread is impersonating.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[CryptographicException: The data protection operation was unsuccessful. This may have been caused by not having the user profile loaded for the current thread's user context, which may be the case when the thread is impersonating.]
Microsoft.Owin.Host.SystemWeb.<>c__DisplayClass1.<GetRethrowWithNoStackLossDelegate>b__0(Exception ex) +27
Microsoft.Owin.Host.SystemWeb.Utils.RethrowWithOriginalStack(Exception ex) +15
Microsoft.Owin.Host.SystemWeb.CallContextAsyncResult.End(IAsyncResult result) +47
Microsoft.Owin.Host.SystemWeb.OwinHttpHandler.EndProcessRequest(IAsyncResult result) +7
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9629708
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155你有什么想法吗?谢谢
发布于 2013-09-13 08:23:53
对于其他访问此页面的人,我也遇到了同样的问题,但解决方案要简单得多。正如上面评论中提到的,公认的答案是糟糕的。还提到,SignalR默认为IProtectedData使用MachineKeyDataProtector。MapHubs和MapConnection都调用函数InitializeProtectedData,该函数向依赖关系解析器注册MachineKeyDataProtector。
我的问题是我正在映射我的SignalR路由,然后配置依赖关系解析器
RouteTable.Routes.MapConnection<SomeEndpoint>("SomeEndpoint", "SomeEndpointUrl");
GlobalHost.DependencyResolver =
new StructureMapDependencyResolver(ObjectFactory.Container);所以基本上,当我注册我的自定义解析器时,由MapConnection -> InitializeProtectedData完成的IProtectedData解析器注册被吹走了。简单的修复,在映射连接之前设置解析器。
GlobalHost.DependencyResolver =
new StructureMapDependencyResolver(ObjectFactory.Container);
RouteTable.Routes.MapConnection<SomeEndpoint>("SomeEndpoint", "SomeEndpointUrl");发布于 2013-04-03 21:44:26
这是一个单独的帖子,允许我使用以下代码解决同样的问题。dfowlers提到要注册一个IProtectedData实例,这让我搜索并找到了定义here。
注在使用Visual Studio开发服务器时不会遇到此问题,但在迁移到live时会遇到此问题。我很高兴我找到了这篇文章,因为我不知道我是如何知道如何实现IProtectedData的。也许文档中有更深层次的东西。
我不确定这是否是100%正确的解决方案,但这对我来说是有效的。我创建了一个实现IProtectedData的类,然后用Ninject注册了它。
类:
using Microsoft.AspNet.SignalR.Infrastructure;
namespace Fwr.DataTeamUploader.Logic
{
public class ProtectedData : IProtectedData
{
// Obviously this isn't doing much to protect the data,
// assume custom encryption required here
// To reiterate, no encryption is VERY^4 BAD, see comments.
public string Protect(string data, string purpose)
{
return data;
}
public string Unprotect(string protectedValue, string purpose)
{
return protectedValue;
}
}
}对象注册:
/// <summary>
/// Load your modules or register your services here
/// </summary>
/// <param name="kernel">The kernel.</param>
private static void RegisterServices(IKernel kernel)
{
...
kernel.Bind<IProtectedData>().To<ProtectedData>();
...发布于 2013-09-04 03:08:48
现在,在本例中,您现在可以使用Microsoft.AspNet.SignalR.SystemWeb包中的扩展方法MapsHubs()。
将使用MachineKeyProtectedData而不是默认实现。
https://stackoverflow.com/questions/15393684
复制相似问题