【发布时间】:2020-10-03 18:49:30
【问题描述】:
我正在配置一个将部署到 Farm 中的 .NETCore 项目。我遵循了添加 DataProction 的所有建议,所以我的代码是这样的:
services.AddMvc(
options =>
{
options.Filters.Add(typeof(AuditAttribute));
options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
options.AddStringTrimmingProvider();
});
var redis = StackExchange.Redis.ConnectionMultiplexer.Connect(Configuration.GetValue<string>("MySuperApp:RedisConnectionString"));
services.AddDataProtection()
.SetApplicationName("MySuperApp")
.ProtectKeysWithDpapi(true)
.PersistKeysToRedis(redis, "DataProtection-Keys");
在开发中,我们只有一个服务器,这工作得很好。我们在 Redis 中只有一个条目,例如:
但是当我们去测试时,我们有两台服务器,我们有以下内容:
另外我们邮箱有如下错误
Exception Type: System.Security.Cryptography.CryptographicException
Exception Message: Error occurred during a cryptographic operation.
Stack Trace: at Microsoft.AspNetCore.DataProtection.Cng.DpapiSecretSerializerHelper.UnprotectWithDpapiCore(Byte* pbProtectedData, UInt32 cbProtectedData, Byte* pbOptionalEntropy, UInt32 cbOptionalEntropy)
at Microsoft.AspNetCore.DataProtection.Cng.DpapiSecretSerializerHelper.UnprotectWithDpapi(Byte[] protectedSecret)
at Microsoft.AspNetCore.DataProtection.XmlEncryption.DpapiXmlDecryptor.Decrypt(XElement encryptedElement)
at Microsoft.AspNetCore.DataProtection.XmlEncryption.XmlEncryptionExtensions.DecryptElement(XElement element, IActivator activator)
at Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager.Microsoft.AspNetCore.DataProtection.KeyManagement.Internal.IInternalXmlKeyManager.DeserializeDescriptorFromKeyElement(XElement keyElement)
Additional Info: An exception occurred while processing the key element ''.
有人可以帮我解决这个问题吗?我们是否缺少服务器上的某些配置?
【问题讨论】:
标签: asp.net-core redis antiforgerytoken data-protection