我们已将Orchard部署到Azure网站。但是,当我们启用我们创建的模块以启用OWIN OpenID连接时,我们会收到此错误:
数据保护操作失败。这可能是由此造成的 没有为当前线程的用户加载用户配置文件 上下文,当线程模仿时可能就是这种情况。
只有在我启用自定义身份验证模块时才会发生这种情况,但它在本地和我们的开发服务器上运行良好。该问题仅发生在Azure中。
堆栈追踪:
[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.] System.Security.Cryptography.ProtectedData.Protect(Byte[] userData, Byte[] optionalEntropy, DataProtectionScope scope) +514 System.Security.Cryptography.DpapiDataProtector.ProviderProtect(Byte[] userData) +75 Microsoft.Owin.Security.DataHandler.SecureDataFormat`1.Protect(TData data) +93 Microsoft.Owin.Security.OpenIdConnect.d__c.MoveNext() +1342 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13877064 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61 Microsoft.Owin.Security.Infrastructure.d__b.MoveNext() +531 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13877064 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61 Microsoft.Owin.Security.Infrastructure.d__8.MoveNext() +631 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13877064 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61 Microsoft.Owin.Security.Infrastructure.d__5.MoveNext() +318 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13877064 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61 System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) +13877209 Microsoft.Owin.Security.Infrastructure.d__0.MoveNext() +1371 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13877064 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61 System.Runtime.CompilerServices.TaskAwaiter.GetResult() +28 Microsoft.Owin.Security.Infrastructure.d__0.MoveNext() +1107 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13877064 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61 Orchard.Mvc.Routes.d__7.MoveNext() in c:\Users\jphillips\code\ifb-blue-orchard\src\Orchard\Mvc\Routes\ShellRoute.cs:181 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13877064 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61 System.Web.TaskAsyncHelper.EndTask(IAsyncResult ar) +69 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +611 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +137
答案 0 :(得分:1)
所以我想出了使用这个Generating reset password token does not work in Azure Website的组合,告诉OWIN使用这个扩展方法来使用自定义的MachineKeyProtectionProvider类。
app.SetDataProtectionProvider(new MachineKeyProtectionProvider());
一旦我设置了OWIN开始使用机器密钥,Azure中的所有内容都知道很酷并且可行。我还写了一篇关于它的post。