【问题标题】:ASP.Net MVC ADAL TokenCache ignoring AfterAccess BeforeAccessASP.Net MVC ADAL TokenCache 忽略 AfterAccess BeforeAccess
【发布时间】:2017-10-20 22:38:39
【问题描述】:

该应用已经运行了好几个月,但昨天我的开发计算机出现了问题(秋季创作者更新),所以检查了我笔记本电脑上的代码并开始工作。但是现在我遇到了一个问题,即应用程序没有将令牌写入缓存数据库。添加一些断点到

void BeforeAccessNotification(TokenCacheNotificationArgs args)
void AfterAccessNotification(TokenCacheNotificationArgs args)
void BeforeWriteNotification(TokenCacheNotificationArgs args)

我可以看到它们永远不会被击中的方法。我的代码与此处的示例代码相同(第 14 行除外,名称不同)

https://github.com/Azure-Samples/active-directory-dotnet-webapp-groupclaims/blob/master/WebApp-GroupClaims-DotNet/Utils/TokenDbCache.cs

我的Startup.Auth.cs和下面的一样(我复制粘贴测试)

https://github.com/Azure-Samples/active-directory-dotnet-webapp-groupclaims/blob/master/WebApp-GroupClaims-DotNet/App_Start/Startup.Auth.cs

我有另一个应用程序,它使用几乎相同的身份验证,它工作正常,我可以看到它在 Startup.Auth 中命中这一行

AuthenticationResult result = await
authContext.AcquireTokenByAuthorizationCodeAsync(
context.Code, new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)), credential, ConfigHelper.GraphResourceId);

然后它运行 BeforeAccessNotification、BeforeWriteNotification、AfterAccessNotification 并且效果很好。

但在非工作应用程序中,即使一切看起来都应该运行,它也不运行上述任何方法。

有什么想法吗?我完全不知所措。

【问题讨论】:

  • 你能比较工作的应用程序和不工作的应用程序来确认区别吗?
  • @c2h0 - 你能在缓存的构造函数上设置断点吗?从您所描述的情况来看,实体框架级别似乎有一些东西(即无法联系数据库?'所以无法检索缓存的信息?

标签: c# asp.net-mvc azure adal


【解决方案1】:

感谢您的回复,问题原来是我的 web.config 中的 key="ida:GraphUrl" 被删除(不知道如何)所以“ConfigHelper.GraphResourceId”在

AuthenticationResult result = await
authContext.AcquireTokenByAuthorizationCodeAsync(
context.Code, new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)), credential, ConfigHelper.GraphResourceId);

是空的,按照我的假设忽略了它

catch (AdalException ex)

会抓到的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多