【问题标题】:GoogleWebAuthorizationBroker.AuthorizeAsync timeout when released to IIS7.0发布到 IIS7.0 时的 GoogleWebAuthorizationBroker.AuthorizeAsync 超时
【发布时间】:2016-04-11 03:37:47
【问题描述】:

我在将代码发布到 IIS7.0 后遇到 GoogleWebAuthorizationBroker.AuthorizeAsync 超时问题。

通过我的开发环境,一切都按预期工作。我看到了 Google 权限屏幕,代码在 App_data 中创建了预期的令牌文件。然后我可以插入和更新日历条目。 但是,当我发布代码时,我从 GoogleWebAuthorizationBroker.AuthorizeAsync 收到请求超时错误。

我已手动将从我的开发环境创建的令牌文件复制到 Web 服务器上,并且代码工作正常。我可以在日历中创建事件。

我已经监控了防火墙,没有任何东西被阻止。

如果我删除 Web 服务器上令牌文件的内容。系统不会提示我重新授权并返回请求超时。

有人对出了什么问题有任何建议吗?

ClientSecrets client = new ClientSecrets
{
    ClientId = SessionState.SystemSettings[SystemSettingKey.GoogleAccountClientId].Value,
    ClientSecret = SessionState.SystemSettings[SystemSettingKey.GoogleAccountClientSecret].Value

};

IList<string> scopes = new List<string>();
scopes.Add(CalendarService.Scope.Calendar);
var credPath = HttpContext.Current.Server.MapPath("~/App_Data/");          
var credential =
    GoogleWebAuthorizationBroker.AuthorizeAsync(client, scopes, account, CancellationToken.None, new FileDataStore(credPath, true))
        .Result;

// Create the calendar service using an initializer instance
BaseClientService.Initializer initializer = new BaseClientService.Initializer
{
    HttpClientInitializer = credential,
    ApplicationName = "App1"
};

【问题讨论】:

  • 请求执行不返回?
  • 在开发环境中它执行并返回,但是当它编译并安装在网络服务器上时,它只是坐在那里等待返回。但是,从我所看到的情况来看,防火墙上没有任何东西被阻止

标签: c# asp.net async-await


【解决方案1】:

我要在这里继续寻找感觉,并说你有一个经典的僵局场景,因为你在这里是blocking on an async method

var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                              client, 
                              scopes, 
                              account,                         
                              CancellationToken.None,
                              new FileDataStore(credPath, true)).Result;

你不应该在异步方法上使用.Result,你应该总是使用await异步等待:

public async Task AuthorizeAsync()
{
   ClientSecrets client = new ClientSecrets
   {
       ClientId = SessionState.
                        SystemSettings[SystemSettingKey.GoogleAccountClientId].Value,
       ClientSecret = SessionState.
                        SystemSettings[SystemSettingKey.GoogleAccountClientSecret].Value

   };

   IList<string> scopes = new List<string>();
   scopes.Add(CalendarService.Scope.Calendar);
   var credPath = HttpContext.Current.Server.MapPath("~/App_Data/");  

   var credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                                 client, 
                                 scopes, 
                                 account,
                                 CancellationToken.None,
                                 new FileDataStore(credPath, true));

   // Create the calendar service using an initializer instance
   BaseClientService.Initializer initializer = new BaseClientService.Initializer
   {
      HttpClientInitializer = credential,
      ApplicationName = "App1"
   };
}

【讨论】:

  • 谢谢你..我认为它在正确的路线上,因为似乎有些人有类似的问题。感谢指点
猜你喜欢
  • 2017-06-14
  • 2016-04-02
  • 1970-01-01
  • 2016-07-29
  • 1970-01-01
  • 2020-08-06
  • 2010-11-08
  • 2013-02-26
  • 2014-05-17
相关资源
最近更新 更多