c# - Azure Active Directory 身份验证损坏 - 没有已知的根本原因

标签 c# asp.net-mvc azure authentication azure-active-directory

我正在构建一个依赖 AAD 的 ASP.NET MVC Web 应用程序授权。我使用标准流程向项目添加身份验证(通过 VS 进行 AAD 身份验证),并且在过去两周内运行得非常好。

今天,突然坏了:

ASP.NET MVC Error ASP.NET MVC Error 2

这发生在 ADALTokenCache 初始化时(标准 AAD 身份验证例程):

public ADALTokenCache(string signedInUserId)
{ 
    // associate the cache to the current user of the web app
    userId = signedInUserId;
    this.AfterAccess = AfterAccessNotification;
    this.BeforeAccess = BeforeAccessNotification;
    this.BeforeWrite = BeforeWriteNotification;
    // look up the entry in the database
    Cache = db.UserTokenCacheList.FirstOrDefault(c => c.webUserUniqueId == userId);
    // place the entry in memory
    this.Deserialize((Cache == null) ? null : MachineKey.Unprotect(Cache.cacheBits,"ADALCache"));
}

看起来很奇怪,根本原因我也不知道——除了添加更多 View 和 Controller 之外,没有对应用程序本身进行任何更改(没有任何事情会干扰身份验证)。

清除浏览器 cookie 不会执行任何操作。手动设置 MachineKey 也没有帮助。

部署应用程序后,此重现将在本地和远程服务器上进行。

有人遇到过这种情况吗?

没有对配置进行任何修改,看起来很奇怪。

最佳答案

解决这个问题的方法是删除数据库。

缓存基于本地MDF文件,并在Web.config中更改其名称:

<add name="DefaultConnection" 
connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-Den-SomeNewName.mdf;Initial Catalog=aspnet-Den-SomeNewName;Integrated Security=True" 
providerName="System.Data.SqlClient" />

关于c# - Azure Active Directory 身份验证损坏 - 没有已知的根本原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33574743/

相关文章:

c# - TransactionScope 中的异常

asp.net-mvc - Html.DisplayFor 和 Html.EditorFor 显示不同的值

c# - 如何在 asp.net mvc 4 中为 select2 字段提供强制字段验证

azure - 具有规模集的基本负载均衡器 "Virtual Machine Scale Set cannot use a basic SKU load balancer when singlePlacementGroup property is false (lar)."

python - 通过Python脚本查看Azure中虚拟机的故障和更新域

C# 正则表达式

c# - Python 和 C# : Is IronPython absolutely necessary?

asp.net-mvc - 大型Web应用程序中Windows Workflow的使用

django - 使用 azuread-oauth2 时,exchange_access_token 上的 openEdx 服务器错误

c# - 使用外部文件或资源?