Azure active directory 使用Azure Active Directory对网站进行加密操作时出错
我正在使用Azure Active Directory登录我的网站 第一次登录很好,但经过一段时间刷新后,我们会收到错误消息: 加密操作期间发生错误。 加密异常:加密操作期间出错。] System.Web.Security.Cryptography.同质化CryptoServiceWrapper.同质化错误(Func`2 Func,字节[]输入)+175 中的Web.Models.ADALTokenCache..ctor(字符串signedInUserId) Web\Models\AdalTokenCache.cs:30 我搜索并找到了一些解决方案,但似乎都不起作用: 通知前:Azure active directory 使用Azure Active Directory对网站进行加密操作时出错,azure-active-directory,Azure Active Directory,我正在使用Azure Active Directory登录我的网站 第一次登录很好,但经过一段时间刷新后,我们会收到错误消息: 加密操作期间发生错误。 加密异常:加密操作期间出错。] System.Web.Security.Cryptography.同质化CryptoServiceWrapper.同质化错误(Func`2 Func,字节[]输入)+175 中的Web.Models.ADALTokenCache..ctor(字符串signedInUserId) Web\Models\AdalTok
try
{
this.Deserialize((Cache == null) ? null : MachineKey.Unprotect(Cache.cacheBits, "ADALCache"));
}
catch (System.Security.Cryptography.CryptographicException cge)
{
db.UserTokenCaches.Remove(Cache);
db.SaveChanges();
}
if (Cache == null)
{
Cache = new UserTokenCache
{
webUserUniqueId = userId,
cacheBits = MachineKey.Protect(this.Serialize(),
"ADALCache"),
LastWrite = DateTime.Now
};
}
//Cache.cacheBits = MachineKey.Protect(this.Serialize(),
"ADALCache");
//Cache.LastWrite = DateTime.Now;
// update the DB and the lastwrite
db.Entry(Cache).State = Cache.UserTokenCacheId == 0 ?
EntityState.Added : EntityState.Modified;
db.SaveChanges();
this.HasStateChanged = false;
事后通知:
try
{
this.Deserialize((Cache == null) ? null : MachineKey.Unprotect(Cache.cacheBits, "ADALCache"));
}
catch (System.Security.Cryptography.CryptographicException cge)
{
db.UserTokenCaches.Remove(Cache);
db.SaveChanges();
}
if (Cache == null)
{
Cache = new UserTokenCache
{
webUserUniqueId = userId,
cacheBits = MachineKey.Protect(this.Serialize(),
"ADALCache"),
LastWrite = DateTime.Now
};
}
//Cache.cacheBits = MachineKey.Protect(this.Serialize(),
"ADALCache");
//Cache.LastWrite = DateTime.Now;
// update the DB and the lastwrite
db.Entry(Cache).State = Cache.UserTokenCacheId == 0 ?
EntityState.Added : EntityState.Modified;
db.SaveChanges();
this.HasStateChanged = false;
您可以分享您正在使用的令牌缓存实现的详细信息吗?我已经从VS2017向导中添加了Azure Active Directory。它在Startup.cs和Startup.Auth.cs中添加了代码。它使用UserTokenCache表插入令牌。似乎错误可能来自您的令牌缓存类的构造函数,您也可以发布它吗?