diff --git a/src/Microsoft.AspNetCore.Authentication/AuthenticationHandler.cs b/src/Microsoft.AspNetCore.Authentication/AuthenticationHandler.cs index 9141e8811d..d0528186c0 100644 --- a/src/Microsoft.AspNetCore.Authentication/AuthenticationHandler.cs +++ b/src/Microsoft.AspNetCore.Authentication/AuthenticationHandler.cs @@ -255,18 +255,15 @@ namespace Microsoft.AspNetCore.Authentication /// This method won't throw exception. Any exception thrown during the authentication will be convert /// to a AuthenticateResult. /// - protected Task HandleAuthenticateOnceSafeAsync() + protected async Task HandleAuthenticateOnceSafeAsync() { try { - return HandleAuthenticateOnceAsync().ContinueWith( - task => task.IsFaulted ? AuthenticateResult.Fail(task.Exception) : task.Result - ); + return await HandleAuthenticateOnceAsync(); } catch (Exception ex) { - // capture exception which is thrown before the task is actually started - return Task.FromResult(AuthenticateResult.Fail(ex)); + return AuthenticateResult.Fail(ex); } }