'''MS-ASPNETCORE-TOKEN' does not match the expected pairing token' when calling deployed .net core API on IIS

I am receiving the following exception in the logs and event viewer when calling an endpoint in a .Net core application (3.1):

'MS-ASPNETCORE-TOKEN' does not match the expected pairing token

I have this application deployed using IIS under the default web site. I had read this exception may be due to a discrepancy with Kestrel and IIS, so I updated the CreateWebHostBuilder() to include UseKestrel() and UseIISIntegration(), specifically in that order.

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
  WebHost.CreateDefaultBuilder(args)
  .ConfigureLogging(logger =>
  {
    logger.ClearProviders();
    logger.AddConsole();
    logger.AddDebug();
    logger.AddEventLog();
  })
  .UseStartup<Startup>()
  .UseKestrel()
  .UseIISIntegration();
}

In the appsettings file, I set the url to "Urls": "http://localhost:5001". This doesn't seem to be respected because navigating to that URL brings up 'This page cannot be displayed.' There is a port provided in the log, but I think this is supposed to be the kestrel port:

Now listening on: http://localhost:20274 Application started. Press Ctrl+C to shut down.

I am calling the endpoint at that port. As an additional note, I have this running with the OutofProcess hosting model.

Any suggestions on troubleshooting or resolution for this issue?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source