2016-04-15 64 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

您也可以點擊如果您已獲取令牌問題,請點擊「清除緩存數據庫」按鈕。