Skip to content
This repository has been archived by the owner on Jun 30, 2023. It is now read-only.

use async controller actions

Jean-Marc Prieur edited this page Jun 12, 2018 · 1 revision

When calling ADAL.NET in an ASP.NET or ASP.NET Core Web Application or Web API controller, you need to make sure that you use the async/await pattern and have your controller actions be async method, otherwise you'll experience multi-threading issues.

In particular you should not use .Result(). See Reminder: Do not call ADAL or MSAL async methods synchronously from the UI thread

Make sure your controller actions be async and return Task<HttpResponseMessage>, and then change the following line to:

var user = await authenticationContext.AcquireTokenXXXAsync()

For more information about the kind of experience you could get if you use .Result, please see Issue #555: Cannot acquire token in web app context

Clone this wiki locally