ASP.NET Core 6 Web API命令行启动IIS Express加载Swagger遇500错误求助
ASP.NET Core 6 Web API 命令行启动IIS Express异常排查
运行现象
- VS2022启动IIS Express正常:可正常加载Swagger页面(
http://localhost:8084/swagger/index.html),请求日志如下:
#Software: Microsoft Internet Information Services 10.0 #Version: 1.0 #Date: YYYY-DD-MM 17:49:22 #Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) sc-status sc-substatus sc-win32-status time-taken YYYY-DD-MM 17:49:22 ::1 GET /_framework/aspnetcore-browser-refresh.js - 8084 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/107.0.0.0+Safari/537.36 http://localhost:8084/swagger/index.html 200 0 0 6 YYYY-DD-MM 17:49:22 ::1 GET /swagger/index.html - 8084 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/107.0.0.0+Safari/537.36 - 200 0 0 3664 YYYY-DD-MM 17:49:22 ::1 GET /_vs/browserLink - 8084 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/107.0.0.0+Safari/537.36 http://localhost:8084/swagger/index.html 200 0 0 59 YYYY-DD-MM 17:49:22 ::1 GET /swagger/v1/swagger.json - 8084 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/107.0.0.0+Safari/537.36 http://localhost:8084/swagger/index.html 200 0 0 149
- 命令行启动IIS Express失败:执行以下命令启动后,Swagger页面返回HTTP 500错误:
"C:\Program Files (x86)\IIS Express\iisexpress" /config:applicationhost.config /site:TheWebApi
请求日志如下:
#Software: Microsoft Internet Information Services 10.0 #Version: 1.0 #Date: 2022-11-19 17:54:41 #Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) sc-status sc-substatus sc-win32-status time-taken 2022-11-19 17:54:41 ::1 GET /swagger/index.html - 8084 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/107.0.0.0+Safari/537.36 - 500 0 574 8 2022-11-19 17:54:41 ::1 GET /favicon.ico - 8084 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/107.0.0.0+Safari/537.36 http://localhost:8084/swagger/index.html 500 0 574 0
错误原因分析
查看系统事件日志,发现核心错误:
Application 'C:\Users\sam\source\repos\WebApplication1\' failed to start. Exception message: Executable was not found at 'C:\Users\sam\source\repos\WebApplication1\bin\Debug\net5.0\WebApplication1.exe'
该项目原本基于.NET 5开发,现已升级至.NET 6,但IIS Express仍在查找.NET 5版本的程序路径,导致启动失败。
配置对比
对比新建的.NET 6 Web API项目(WebApplication2)的applicationhost.config,现有项目(WebApplication1)的站点配置段如下:
<site name="WebApplication1" id="2"> <application path="/" applicationPool="WebApplication1 AppPool"> <virtualDirectory path="/" physicalPath="C:\Users\sam\source\repos\WebApplication1" /> </application> <bindings> <binding protocol="http" bindingInformation="*:8084:localhost" /> </bindings> </site>
提问
由于希望不依赖VS2022启动服务,是否应将physicalPath修改为C:\Users\sam\source\repos\WebApplication1\bin\Debug\net6.0?
内容的提问来源于stack exchange,提问作者Sam Carleton
相关产品推荐
相关产品推荐

