1

Developing a Dotnet Framework 4.8 REST API in VS2019 and starting IIExpress that way is no problem.
GET http://localhost:51241/api/user returns correct data.

So I start IIExpress from the command line
but then GET http://localhost:8080/api/user returns a 404.
Why?


Command line: & 'C:\Program Files (x86)\IIS Express\iisexpress.exe' /path:C:\DATA\Nav\bin\

GET http://localhost:8080/ returns a 403.14 (not allowed to browse) which is correct.


A clue can be the output:

Copied template config file 'C:\Program Files\IIS Express\AppServer\applicationhost.config' to 'C:\Users\User\AppData\Local\Temp\iisexpress\applicationhost2020130173241776.config'
Updated configuration file 'C:\Users\User\AppData\Local\Temp\iisexpress\applicationhost2020130173241776.config' with given cmd line info.
Starting IIS Express ...
Successfully registered URL "http://localhost:8080/" for site "Development Web Site" application "/"
Registration completed
IIS Express is running.
Enter 'Q' to stop IIS Express

as my site is not called "Development Web Site" but "Nav".
Another clue is that may call results in copies from 'C:\Program Files\IIS Express\AppServer\applicationhost.config' while VS2019 seems to use 'C:\DATA\Nav.vs\Nav\config\applicationhost.config'

The applicationhost.config file IISExpress copies from, is not the same as VS2019 uses as my, failed, run copies from 'C:\Program Files\IIS Express\AppServer\applicationhost.config' but VS2019 seems to use 'C:\DATA\Nav.vs\Nav\config\applicationhost.config'

LosManos
  • 7,195
  • 6
  • 56
  • 107
  • 1
    It looks like it's ignoring the copied applicationhost.config. Have you looked at this https://stackoverflow.com/questions/21202885/how-can-i-change-iis-express-port-for-a-site – tlbignerd Jan 30 '20 at 18:18
  • 1
    https://learn.microsoft.com/en-us/iis/extensions/using-iis-express/running-iis-express-from-the-command-line#running-a-site-using-iis-express-from-the-command-line You must use an explicit `/config` switch, and also point to `C:\DATA\Nav.vs\Nav\config\applicationhost.config` as VS does. The issue you observed was caused by the fact that IIS Express without `/config` switch loads its own default config file, which does not contain your site at all. – Lex Li Jan 30 '20 at 18:21
  • Your kind words and a dinner and some brain cool down time made me read the docs properly again and realise that the `/config:` flag was for the `applicationhost.config` and not the the site's config. So calling `& 'C:\Program Files (x86)\IIS Express\iisexpress.exe' /config:C:\DATA\Nav\.vs\Nav\config\applicationhost.config /site:Nav` made it work as expected. – LosManos Jan 30 '20 at 19:43

1 Answers1

1

The tricky part to simulate VS launching IIS Express is that you must call IIS Express command line with the correct /config switch pointing to the applicationHost.config file generated by VS (hidden in .vs folder, for VS2015 and above).

Reference

Lex Li
  • 60,503
  • 9
  • 116
  • 147