我試圖在Azure中運行的基於OWIN/Katana的ASP.NET MVC網站上實現密碼重置。使用OWIN/Katana在Azure上的數據保護操作失敗
它在本地運行時工作正常,但在生產中失敗。
我創建了一個UserToken提供商
userManager.UserTokenProvider = new DataProtectorTokenProvider<ApplicationUser>(provider.Create("PasswordReset"))
但是,當我試圖生成令牌如下我會在年底異常顯示。
var resetToken = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
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.
at System.Security.Cryptography.ProtectedData.Protect(Byte[] userData, Byte[] optionalEntropy, DataProtectionScope scope)
at System.Security.Cryptography.DpapiDataProtector.ProviderProtect(Byte[] userData)
at System.Security.Cryptography.DataProtector.Protect(Byte[] userData)
at Microsoft.Owin.Security.DataProtection.DpapiDataProtector.Protect(Byte[] userData)
at Microsoft.AspNet.Identity.Owin.DataProtectorTokenProvider`2.<GenerateAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Identity.UserManager`2.<GenerateUserTokenAsync>d__e9.MoveNext()
您是否找到了解決方案? – Dragouf
請注意。有任何想法嗎? –
是的,我找到了解決方法,但我並不完全滿意。看起來這是由於應用程序中的AppName參數不同。所以我使用OwinStartupAttribute的配置(IAppBuilder應用程序)調用的應用參數來實例化IDataPRovider,它似乎工作。要獲取數據提供者對象,可以這樣做:app.GetDataProtectionProvider()。告訴我它是否可以工作 – Dragouf