调用ApplicationTokenProvider.LoginSilentAsync永不返回 [英] Call to ApplicationTokenProvider.LoginSilentAsync never returns
问题描述
在我的本地PC上,我尝试使用以下代码连接到AzureBillingAPI:
From my local PC I'm trying to connect to the AzureBillingAPI using the following code :
var serviceCreds = await ApplicationTokenProvider.LoginSilentAsync(tenantDomain, clientId, secret);
此方法永远不会返回.调试输出显示以下内容:
This methods never returns. Debug output displays the following :
Microsoft.IdentityModel.Clients.ActiveDirectory详细信息:1:07/03/2017 14:02:07:e608ec23-675f-4828-aa65-72479409ec63-TokenCache:查找缓存以获取令牌...
Microsoft.IdentityModel.Clients.ActiveDirectory Verbose: 1 : 07/03/2017 14:02:07: e608ec23-675f-4828-aa65-72479409ec63 - TokenCache: Looking up cache for a token...
iisexpress.exe信息:0:07/03/2017 14:02:07:e608ec23-675f-4828-aa65-72479409ec63-TokenCache:在缓存中查找令牌...
iisexpress.exe Information: 0 : 07/03/2017 14:02:07: e608ec23-675f-4828-aa65-72479409ec63 - TokenCache: Looking up cache for a token...
Microsoft.IdentityModel.Clients.ActiveDirectory信息:2:07/03/2017 14:02:07:e608ec23-675f-4828-aa65-72479409ec63-令牌缓存:在缓存中找不到匹配的令牌
Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 : 07/03/2017 14:02:07: e608ec23-675f-4828-aa65-72479409ec63 - TokenCache: No matching token was found in the cache
iisexpress.exe信息:0:07/03/2017 14:02:07:e608ec23-675f-4828-aa65-72479409ec63-令牌缓存:在缓存中找不到匹配的令牌
iisexpress.exe Information: 0 : 07/03/2017 14:02:07: e608ec23-675f-4828-aa65-72479409ec63 - TokenCache: No matching token was found in the cache
问题:我该如何连接?谢谢.
Question: how do I connect ? Thanks.
推荐答案
根据您的描述,我猜想此方法永远不会返回的原因是您在带有等待关键字的sync Controller方法中将async方法称为了.
According to your description, I guess the reason why this methods never returns is you called the async method in the sync Controller method with wait keywords.
如果按如下所示调用getResultAsync,它将永远不会返回结果:
If you call the getResultAsync as below, it will never return the result :
public ActionResult Index()
{
getResultAsync().Wait();
return View();
}
public static async Task getResultAsync()
{
string subscription = "subid";
string tenantid = "tenantid ";
string clientId = "clientId ";
string key = "key";
var serviceCreds = await ApplicationTokenProvider.LoginSilentAsync(tenantDomain, clientId, key);
BillingManagementClient b1 = new BillingManagementClient(serviceCreds) { SubscriptionId = subscription };
var result = b1.Operations.List();
}
我建议您可以如下更改索引方法,它将很好地工作:
I suggest you could change the index method as below, it will work well:
public async Task<ActionResult> Index()
{
await getResultAsync();
return View();
}
结果:
这篇关于调用ApplicationTokenProvider.LoginSilentAsync永不返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!