Ross Kelly
Ross Kelly

Reputation: 567

ASP.NET Core 8 - Cannot debug using IIS Express

UPDATE:

I forgot to add the default controller route/endpoint in config. Adding the following code to Program.cs solves the problem but I do get a warning message that says "Suggest using top level route registrations instead of UseEndpoints.

app.UseEndpoints(endpoints =>
{
    endpoints.MapControllerRoute(
        name: "default",
        pattern: "{controller=Home}/{action=Index}/{id?}");
});

ORIGINAL ISSUE:

I've created a new ASP.NET Core 8.0 MVC web app and populated it with controllers, views, models, classes, etc from an older Core 3.1 project.

The project compiles ok but I cannot debug using IIS Express. I remember having the same problems when first using VS 2019. However, I did manage to get it working. I'm now on VS 2022 and when I try to run/debug the project with IIS Express I get the following error in Chrome:

This localhost page can't be found. No webpage was found for the web address: https://localhost:44389/

I've tried changing various port numbers but I end with with further errors about not being able to register the port number.

If I create a new blank/default ASP.NET Core 8 MVC test app in VS2022 it runs/debugs in IIS Express fine without issue.

Project Settings -> Debug -> Launch profiles

IIS Express App URL: http://localhost:58088

App SSL URL: https://localhost:44389 (grayed out cannot be changed)

Use SSL: Checked

launchSettings.json

{
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:1191",
      "sslPort": 44389
    }
  },
  "profiles": {
    "http": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "applicationUrl": "http://localhost:5099",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "https": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "applicationUrl": "https://localhost:7247;http://localhost:5099",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

Upvotes: 1

Views: 763

Answers (1)

Jalpa Panchal
Jalpa Panchal

Reputation: 12769

New warning you are getting is saying you can directly use the MapControllerRoute method in the app configuration section, without the UseEndpoints method as shown below:

app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");

enter image description here

You could refer this link for more detail:

ASP0014: Suggest using top level route registrations

And regarding the original issue it seems configuration issues in the launchSettings.json or a mismatch in the expected URLs/routes.Your solution to add a default controller route in Program.cs was on right direction, as it explicitly defines the routing pattern ASP.NET Core should use to resolve URLs to controllers and actions, this will help application know how to handle incoming requests.

Upvotes: 2

Related Questions