You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ASP.NET Core 8无法使用IIS Express调试问题及解决办法

ASP.NET Core 8 MVC迁移后IIS Express调试404问题解决

问题描述

将旧版Core 3.1项目的控制器、视图、模型等内容迁移至新创建的ASP.NET Core 8.0 MVC项目后,编译正常,但使用IIS Express调试时,Chrome浏览器报错:

无法找到此localhost页面。未找到对应网址的网页:https://localhost:44389/

尝试修改端口号时出现端口注册失败的情况,而直接在VS2022中创建的全新默认ASP.NET Core 8 MVC测试应用,可正常使用IIS Express运行调试。

项目调试配置信息:

  • 启动配置文件:IIS Express
  • 应用URL:http://localhost:58088
  • 应用SSL URL:https://localhost:44389(灰色不可修改)
  • 启用SSL:已勾选

项目的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"
      }
    }
  }
}

解决方案

问题根源是项目中缺少默认控制器路由/端点的配置。

推荐写法(无编译器警告)

ASP.NET Core 8推荐使用顶级路由注册替代传统的UseEndpoints写法,在Program.cs中添加以下代码即可解决问题:

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

兼容写法(有编译器警告)

如果暂时需要保留旧版写法,也可以使用以下代码,但会收到“建议使用顶级路由注册替代UseEndpoints”的警告:

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

内容的提问来源于stack exchange,提问作者Ross Kelly

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 07:35:13