Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么office 365登录缓存显示空值?_C#_Asp.net Mvc_Office365 - Fatal编程技术网

C# 为什么office 365登录缓存显示空值?

C# 为什么office 365登录缓存显示空值?,c#,asp.net-mvc,office365,C#,Asp.net Mvc,Office365,嗨 我正在使用office 365登录以访问日历,我已将服务添加到我的项目中,工作正常,没有任何问题,我已清除数据库并再次运行项目我无法获取日历事件,无法访问,因为缓存显示空值,我已再次添加服务,但缓存仍显示空值,你能请任何人帮我解决这个问题,我给我的代码如下 UserTokenCache Cache; // constructor public ADALTokenCache(string user) {

我正在使用office 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);
                        },
谢谢,
卡提克

我已清除数据库并再次运行项目,但无法获取日历事件

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

如果这不起作用,您还可以在GitHub上运行my来解决此问题

步骤1下载示例项目

步骤#2在Office 365租户广告下注册应用程序(如果已注册应用程序,请跳过),声明Office 365 Exchange Online>读取用户邮件权限并将回复URL设置为“”。

步骤#3在web.config文件中,从Azure AD portal复制ClientId、TenantId和客户端机密

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

预期结果如下:

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