Optimizing async tasks (ConfigureAwait(false))
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace AMWD.Common.AspNetCore.Security.BasicAuthentication
|
||||
string password = plain[(username.Length + 1)..];
|
||||
|
||||
var ipAddress = Context.GetRemoteIpAddress();
|
||||
principal = await validator.ValidateAsync(username, password, ipAddress, Context.RequestAborted);
|
||||
principal = await validator.ValidateAsync(username, password, ipAddress, Context.RequestAborted).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -51,14 +51,14 @@ namespace AMWD.Common.AspNetCore.Security.BasicAuthentication
|
||||
string username = plain.Split(':').First();
|
||||
string password = plain[(username.Length + 1)..];
|
||||
|
||||
var principal = await validator.ValidateAsync(username, password, httpContext.GetRemoteIpAddress(), httpContext.RequestAborted);
|
||||
var principal = await validator.ValidateAsync(username, password, httpContext.GetRemoteIpAddress(), httpContext.RequestAborted).ConfigureAwait(false);
|
||||
if (principal == null)
|
||||
{
|
||||
SetAuthenticateRequest(httpContext, validator.Realm);
|
||||
return;
|
||||
}
|
||||
|
||||
await next.Invoke(httpContext);
|
||||
await next.Invoke(httpContext).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -37,14 +37,14 @@ namespace AMWD.Common.AspNetCore.Security.PathProtection
|
||||
{
|
||||
if (httpContext.Request.Path.StartsWithSegments(path))
|
||||
{
|
||||
var result = await authorizationService.AuthorizeAsync(httpContext.User, null, policyName);
|
||||
var result = await authorizationService.AuthorizeAsync(httpContext.User, null, policyName).ConfigureAwait(false);
|
||||
if (!result.Succeeded)
|
||||
{
|
||||
await httpContext.ChallengeAsync();
|
||||
await httpContext.ChallengeAsync().ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
await next.Invoke(httpContext);
|
||||
await next.Invoke(httpContext).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,8 +87,8 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
|
||||
if (!string.IsNullOrWhiteSpace(hostUrl))
|
||||
client.DefaultRequestHeaders.Referrer = new Uri(hostUrl);
|
||||
|
||||
var response = await client.GetAsync(source);
|
||||
fileBytes = await response.Content.ReadAsByteArrayAsync();
|
||||
var response = await client.GetAsync(source).ConfigureAwait(false);
|
||||
fileBytes = await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -109,7 +109,7 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
|
||||
try
|
||||
{
|
||||
string path = Path.Combine(env.WebRootPath, source);
|
||||
fileBytes = await File.ReadAllBytesAsync(path);
|
||||
fileBytes = await File.ReadAllBytesAsync(path).ConfigureAwait(false);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user