gpt4 book ai didi

c# - GoogleWebAuthorizationBroker.AuthorizeAsync 发布到 IIS7.0 时超时

转载 作者:太空宇宙 更新时间:2023-11-03 13:04:28 27 4
gpt4 key购买 nike

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

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

我已经手动复制了一个从我的开发环境创建的 token 文件到网络服务器上,代码工作正常。我可以在日历中创建事件。

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

如果我删除网络服务器上 token 文件的内容。没有提示我重新授权,我返回请求超时。

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

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"
};

最佳答案

我要在这里继续寻找感觉并说你自己有一个经典的僵局场景,因为你是 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"
};
}

关于c# - GoogleWebAuthorizationBroker.AuthorizeAsync 发布到 IIS7.0 时超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31244701/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com