-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Closed
Labels
BlazorPri1Source - Docs.msDocs Customer feedback via GitHub IssueDocs Customer feedback via GitHub Issueaspnet-core/svcblazor/subsvcdoc-bug
Description
Description
In one of the code example:
public class TokenHandler(IHttpContextAccessor httpContextAccessor) :
DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request, CancellationToken cancellationToken)
{
var accessToken = httpContextAccessor.HttpContext?
.GetTokenAsync("access_token").Result ??
throw new Exception("No access token");
request.Headers.Authorization =
new AuthenticationHeaderValue("Bearer", accessToken);
return await base.SendAsync(request, cancellationToken);
}
}
Why do you guys recommend to access .Result instead of awaiting the Task?
I know many developers often copy and paste code without much thought, and their project might have become another victim of that pattern, unless it was intentional.
Page URL
Content source URL
Document ID
c3346d3a-346b-8db4-2650-ec044b3f0dd9
Platform Id
1dd51a4e-f734-569f-f6e9-19a27bcd9f4d
Article author
Metadata
- ID: c3346d3a-346b-8db4-2650-ec044b3f0dd9
- PlatformId: 1dd51a4e-f734-569f-f6e9-19a27bcd9f4d
- Service: aspnet-core
- Sub-service: blazor
Metadata
Metadata
Assignees
Labels
BlazorPri1Source - Docs.msDocs Customer feedback via GitHub IssueDocs Customer feedback via GitHub Issueaspnet-core/svcblazor/subsvcdoc-bug
Type
Projects
Status
Done