2016-04-15 65 views
0

嗨,为什么office 365登录缓存显示空值?

我正在办公室365登录访问日历,我已经将服务添加到我的项目,它工作正常没有任何问题,我已清除我的数据库,并再次运行我无法获得的项目日历事件,它是不可访问的,因为缓存显示空值,我又添加了服务,但它仍然显示缓存的空值,你可以请任何人帮我解决这个问题,我给我下面的代码。

 UserTokenCache Cache; 

     // constructor 
     public ADALTokenCache(string user) 
     { 
      // associate the cache to the current user of the web app 
      User = user; 
      this.AfterAccess = AfterAccessNotification; 
      this.BeforeAccess = BeforeAccessNotification; 
      this.BeforeWrite = BeforeWriteNotification; 


      // look up the entry in the DB 
      Cache = db.UserTokenCacheList.FirstOrDefault(c => c.webUserUniqueId == User); 
      // place the entry in memory 
      this.Deserialize((Cache == null) ? null : Cache.cacheBits); 
     } 



     AuthorizationCodeReceived = (context) => 
         { 

          var code = context.Code; 

          ClientCredential credential = new ClientCredential(SettingsHelper.ClientId, SettingsHelper.ClientSecret); 
          String UserObjectId = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.NameIdentifier).Value; 

          AuthenticationContext authContext = new AuthenticationContext(SettingsHelper.Authority, new ADALTokenCache(UserObjectId)); 

          authContext.AcquireTokenByAuthorizationCode(code, new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)), credential, SettingsHelper.AADGraphResourceId); 

          return Task.FromResult(0); 
         }, 

感谢,
KARTHIK

回答

0

我已经清除我的数据库,并再次运行该项目,我无法得到日历事件

在这种情况下,你需要注销并再次登录,以便新缓存将存储在数据库中。

如果这不起作用,您也可以在GitHub上运行我的AspNetMvc-with-O365 project来解决此问题。

步骤#1下载示例项目AspNetMvc-with-O365.zip

步骤2在Office 365租户AD下注册应用程序(如果您有应用程序注册,则跳过),声明Office 365 Exchange Online>读取用户邮件权限并将REPLY URL设置为“http://localhost:2659/”。 enter image description here

步骤3在web.config文件中,复制Azure AD门户中的ClientId,TenantId和Client Secret。

enter image description here

第4步运行Visual Studio中的项目,并登录使用Azure的AD帐户

预期的结果应该是如下:

enter image description here

您也可以点击如果您已获取令牌问题,请点击“清除缓存数据库”按钮。