[英]Starting IIS Express cmd rather than VS2022
The ASP.Net Core 6 Web Api runs under IIS Express via VS2022 just fine and allows me to load the swagger page (http://localhost:8084/swagger/index.html): ASP.Net Core 6 Web Api 通过 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
When running it from the cmdline:从 cmdline 运行它时:
"C:\Program Files (x86)\IIS Express\iisexpress" /config:applicationhost.config /site:TheWebApi
Swagger does not load returning a HTTP 500: Swagger 不加载返回 HTTP 500:
#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
Lex Li's blog How Visual Studio Launches IIS Express to Debug ASP.NET Core Apps was very helpful in me gaining more information on what is going on. Lex Li 的博客How Visual Studio Launches IIS Express to Debug ASP.NET Core Apps对我获得有关正在发生的事情的更多信息非常有帮助。 Clearly, VS2022 is doing some magic to make things run in debug mode.显然,VS2022 正在施展魔法,让事情在调试模式下运行。 In my case, I am trying to get a desktop app to launch the ASP.Net Core 6 application, so debugging is not a concern.就我而言,我正在尝试获取桌面应用程序来启动 ASP.Net Core 6 应用程序,因此调试不是问题。 When I looked into the event log, I found what might be the problem, but don't know the solution:当我查看事件日志时,我发现可能是什么问题,但不知道解决方案:
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'
The problem is the application is.Net 6, not.Net 5. It was originally.Net 5, but it has been upgraded to.Net 6. This has me thinking...问题是应用程序是.Net 6,不是.Net 5。它最初是.Net 5,但已经升级到.Net 6。这让我想到了......
I did just create a new.Net WebApi project (WebApplication2) to compare the applicationhost.conf generated vs the real project (WebApplication1).我只是创建了一个新的 .Net WebApi 项目 (WebApplication2) 来比较生成的 applicationhost.conf 与真实项目 (WebApplication1)。 The WebApplication1 has the following section which was not in WebApplicaiton2: WebApplication1 具有以下不在 WebApplicaiton2 中的部分:
<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>
Since I don't want Visual Studio 2022 to be taken into account, should physicalPath="C:\Users\sam\source\repos\WebApplication1\bin\Debug.net6.0"?由于我不想考虑 Visual Studio 2022,因此 physicalPath="C:\Users\sam\source\repos\WebApplication1\bin\Debug.net6.0" 应该吗?
In my particular case, there is a desktop application that is managing the execution of the ASP.Net Core 6 Web API application in question.在我的特殊情况下,有一个桌面应用程序正在管理所讨论的 ASP.Net Core 6 Web API 应用程序的执行。 It turns out that it is possible to publish the ASP.Net Core 6 Web API application into a single EXE, which is called a Self-contained deployment .事实证明,可以将 ASP.Net Core 6 Web API 应用程序发布到单个 EXE 中,这称为Self-contained deployment 。 This is what I needed.这就是我需要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.