VS 2022 + .NET Core 3.1 Web app can't debug under IIS profile

Suren Manawatta 21 Reputation points
2023-04-21T04:40:55.7033333+00:00

I receive the following error when trying to debug the .NET core web app under the IIS profile. 11

launchSettings.json is as follows, and the PC IP is correct. (192.168.31.107) 22

"cqrs" site is also created in IIS and with a separate app pool (CLR version: No managed code). The URL (http://192.168.31.107/cqrs/swagger/index.html) also works when typed into the browser. The only issue is that when I hit F5 from VS 2022, I get the popup error and can't debug. I hope this information is enough for you to let me know how to fix this. Please don't hesitate to ask for more information; I'll be happy to provide it. If I change the application URL to "http://localhost/cqrs" then the VS2022 lets me hit F5 and debug. But I want the web app to run with the IP, not with localhost. I found a similar question and tried everything. Nothing works.

Internet Information Services
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,400 questions
ASP.NET API
ASP.NET API
ASP.NET: A set of technologies in the .NET Framework for building web applications and XML web services.API: A software intermediary that allows two applications to interact with each other.
318 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Sam Wu-MSFT 7,286 Reputation points Microsoft Vendor
    2023-04-26T09:29:22.2333333+00:00

    @Suren Manawatta You can try to create a new launch profile to add development-time IIS support:

    1. Right-click the project in Solution Explorer. Select Properties. Open the Debug tab.
    2. For Profile, select the New button. Name the profile "IIS" in the popup window. Select OK to create the profile.
    3. For the Launch setting, select IIS from the list.
    4. Select the checkbox for Launch browser and provide the endpoint URL. When the app requires HTTPS, use an HTTPS endpoint (https://). For HTTP, use an HTTP (http://) endpoint. Provide the same host name and port as the IIS configuration specified earlier uses, typically localhost. Provide the name of the app at the end of the URL. For example, https://localhost/WebApplication1 (HTTPS) or http://localhost/WebApplication1 (HTTP) are valid endpoint URLs.
    5. In the Environment variables section, select the Add button. Provide an environment variable with a Name of ASPNETCORE_ENVIRONMENT and a Value of Development.
    6. In the Web Server Settings area, set the App URL to the same value used for the Launch browser endpoint URL.
    7. For the Hosting Model setting in Visual Studio 2019 or later, select Default to use the hosting model used by the project. If the project sets the <AspNetCoreHostingModel> property in its project file, the value of the property (InProcess or OutOfProcess) is used. If the property isn't present, the default hosting model of the app is used, which is in-process. If the app requires an explicit hosting model setting different from the app's normal hosting model, set the Hosting Model to either In Process or Out Of Process as needed.
    8. Save the profile. You should now be able to debug your application with IIS. Make sure to set your build configuration to Debug, and the profile to IIS. Then click the run button to start your application. More information you can refer to this link: IIS launch profile.

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.