1
0

Optimizing async tasks (ConfigureAwait(false))

This commit is contained in:
2023-11-03 10:12:30 +01:00
parent 18b9627ea4
commit ca76966827
11 changed files with 61 additions and 43 deletions

View File

@@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Authorization
var logger = context.HttpContext.RequestServices.GetService<ILogger<BasicAuthenticationAttribute>>();
try
{
var validatorResult = await TrySetHttpUser(context);
var validatorResult = await TrySetHttpUser(context).ConfigureAwait(false);
bool isAllowAnonymous = context.ActionDescriptor.EndpointMetadata.OfType<AllowAnonymousAttribute>().Any();
if (isAllowAnonymous)
return;
@@ -111,7 +111,7 @@ namespace Microsoft.AspNetCore.Authorization
if (validator == null)
return null;
var result = await validator.ValidateAsync(username, password, context.HttpContext.GetRemoteIpAddress(), context.HttpContext.RequestAborted);
var result = await validator.ValidateAsync(username, password, context.HttpContext.GetRemoteIpAddress(), context.HttpContext.RequestAborted).ConfigureAwait(false);
if (result == null)
return null;

View File

@@ -66,8 +66,8 @@ namespace Microsoft.AspNetCore.Mvc.Filters
if (string.IsNullOrWhiteSpace(privateKey))
return;
await DoValidation(context);
await base.OnActionExecutionAsync(context, next);
await DoValidation(context).ConfigureAwait(false);
await base.OnActionExecutionAsync(context, next).ConfigureAwait(false);
}
private async Task DoValidation(ActionExecutingContext context)
@@ -82,7 +82,7 @@ namespace Microsoft.AspNetCore.Mvc.Filters
return;
}
await Validate(context, token);
await Validate(context, token).ConfigureAwait(false);
}
private async Task Validate(ActionExecutingContext context, string token)
@@ -93,8 +93,8 @@ namespace Microsoft.AspNetCore.Mvc.Filters
{ "secret", privateKey },
{ "response", token }
};
var response = await httpClient.PostAsync(VerificationUrl, new FormUrlEncodedContent(param));
string json = await response.Content.ReadAsStringAsync();
var response = await httpClient.PostAsync(VerificationUrl, new FormUrlEncodedContent(param)).ConfigureAwait(false);
string json = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var result = JsonConvert.DeserializeObject<Response>(json);
if (result?.Success != true)