question

AzureDevUser-7572 avatar image
0 Votes"
AzureDevUser-7572 asked YijingSun-MSFT edited

Azure AD authentication PublicClientApplication builder not working after deploying to IIS

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

azure-active-directory
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

0 Answers