You have an ASP.NET Core web app using Microsoft.Identity.Web to sign in users and acquire tokens to call a downstream API. The app runs on multiple App Service instances behind a load balancer and frequently scales out. Users are prompted to sign in more often than expected, and AcquireToken calls are hitting the network frequently after scale events. What should you implement to improve token reuse across instances? Choose two.
Choose an answer
Tap an option to check your answer.
Correct answer: Configure Microsoft.Identity.Web to use AddDistributedTokenCaches and back it with Azure Cache for Redis as the IDistributedCache provider., Implement MSAL token cache serialization to a shared store (such as Redis or SQL) for confidential client flows and Web APIs using MSAL extensions..
Why this is the answer
The problem describes frequent sign-in prompts and network calls for tokens after scaling, indicating token cache invalidation or loss across instances. Configuring Microsoft.Identity.Web to use AddDistributedTokenCaches with Azure Cache for Redis (or any IDistributedCache provider) centralizes the token cache. This allows all instances to share the same cached tokens, preventing re-authentication and re-acquiring tokens when a user's request is routed to a different instance after a scale event. Similarly, implementing MSAL token cache serialization to a shared store like Redis or SQL directly addresses the issue by persisting the token cache outside of individual application instances. This ensures that cached tokens are accessible to any instance of the application, improving token reuse and reducing network calls to Azure AD. Using MSAL’s default in-memory cache with sticky sessions is a partial solution; while it helps keep a user on one instance, it doesn't solve the problem if that instance restarts or if sticky sessions fail. Disabling the token cache would worsen the problem by forcing network calls for every token request, increasing latency and load.
Pass your exam — without the endless answer hunt
Get every verified question and explanation for this exam in one place, and save hours of prep. 1,000+ certifications · 20+ languages · free to start.
Pass your exam faster → No card needed