简体   繁体   中英

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):

#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:

"C:\Program Files (x86)\IIS Express\iisexpress" /config:applicationhost.config /site:TheWebApi

Swagger does not load returning a 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. Clearly, VS2022 is doing some magic to make things run in debug mode. 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. 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...

I did just create a new.Net WebApi project (WebApplication2) to compare the applicationhost.conf generated vs the real project (WebApplication1). The WebApplication1 has the following section which was not in 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"?

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. 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 . This is what I needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM