Share via

Microsoft Graph with Web Forms

Deepa Vasudev 6 Reputation points
2020-08-22T19:44:43.737+00:00

I am trying to add MSAL azure AD single tenant authentication to my existing ASPNET WebForms application. I followed

https://learn.microsoft.com/en-us/learn/modules/msgraph-build-aspnetmvc-apps/5-exercise-add-auth

I created a ASP.NET Web Application (WebForms, MVC, Web API) and followed the above article. When I use MVC as created by this article it works just fine. I am able to login and see my name and mail with signout link.

If I disable Routing to MVC default Home(created with above example), and let WebForms default.aspx page loads, it loads fine. but when I click login (it is coded to signin from master page link), I am getting login page of OpenID connect.

When I signin the OnAuthorizationCodeReceivedAsync method, throws an error in this line.

var result = await idClient.AcquireTokenByAuthorizationCode(
scopes, notification.Code).ExecuteAsync();

BeforeAccessNotification, AfterAccessNotification methods throw Object reference not set exception for

httpContext.Session[tokenCacheKey], while userId based tokenCacheKey value is available in variable. httpcontext is HttpContext.Current is null.

How to resolve this error.

Microsoft Security | Microsoft Entra | Microsoft Entra ID

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.