Azure AD authentication PublicClientApplication builder not working after deploying to IIS

AzureDevUser 1 Reputation point
2021-09-30T09:58:24.63+00:00

I have the following code to authenticate from azure which works fine with IIS express but the same when I am deploying to IIS it is getting request time out

IPublicClientApplication app = PublicClientApplicationBuilder.Create(azMapping.ClientId)
.WithAuthority(authority).WithRedirectUri("**http://localhost:44342/Default.aspx"**).Build();

var accounts = app.GetAccountsAsync().GetAwaiter().GetResult();
 var options = new SystemWebViewOptions()
 {
    OpenBrowserAsync = SystemWebViewOptions.OpenWithEdgeBrowserAsync
 };
 AuthenticationResult result = null;
 if (accounts.Any())
 {
    result = app.AcquireTokenSilent(scopes, accounts.FirstOrDefault())
    .ExecuteAsync().GetAwaiter().GetResult();
 }
 else
 {
   try
   {
      result = app.AcquireTokenInteractive(scopes).WithSystemWebViewOptions(options).ExecuteAsync(CancellationToken.None).GetAwaiter().GetResult();
    if (result != null)
    {
      var accounts1 = app.GetAccountsAsync().GetAwaiter().GetResult();
    }
  }
  catch (MsalUiRequiredException ex)
  {

  }
 }

when I had this http://localhost/TestAz/default.aspx it is not working. From IIS express I am able to navigate to Portal azure site and authentication was successful. But some how it is not working after hosting to IIS

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,342 questions
0 comments No comments
{count} votes