Aspnetcore: How to run WebAPi on IISExpress using command line

Created on 21 Oct 2015  ·  12Comments  ·  Source: dotnet/aspnetcore

I have two solutions: The one is a service [asp.net 5 API] and the other is the client [.NET console application]. I want the service will run every time I run the client.

My machine is win10 x64 with VS2015 installed, and Web tools beta 8 installed.

I tried this command:

C:\Program Files (x86)\IIS express>iisexpress /config:C:\..[my project folder]..\.vs\config\applicationhost.config /site:mySiteName
IIS Express is running.
Enter 'Q' to stop IIS Express

But when I send a requeste I get:

Request started: "GET" http://localhost:53745/
Request ended: http://localhost:53745/ with HTTP status 502.3

If I run iisexpress /path:.....wwwroot I get another exception: 502.19

I tried run the command with trace:debug, but I doesn't help.

Thanks you for any help.

Most helpful comment

@najoshi83 that command doesn't run IIS - it runs locally hosted. Has anyone figured out how to get IISExpress command line working? I need it because JWT Bearer Authentication doesn't work with Kestrel self hosted, and VS Tooling for F# in an ASP.NET Core project is not there yet. VS Code + CLI is what we need to use, but for the IISExpress issue.

All 12 comments

I Found the solution:

"C:\Users\MY_USER_NAME\.dnx\runtimes\dnx-clr-win-x86.1.0.0-beta8\bin\dnx.exe" --appbase "MY_SOLUTION_FOLDER\src\MY_PROJECT" "Microsoft.Dnx.ApplicationHost" --configuration Debug "COMMAND_FROM_PROJECT.JSON" ```

@YehudahA I think the Microsoft.Dnx.ApplicationHost is another host method not iisexpress. I could be wrong, still new to this. There are 3 ways to host an application via IISPlatform(iis, iisexpress), Kestrel and applicationhost.

That's not the solution...

Hi!
After trial and error, I changed my code something like this:

"C:\Users\...\dnx.exe" -p C:\Users\src\myproject "web"

I save it in a xxx.cmd file, anr run it every time that I want run my client project.
But, I don't know how to set the port end environment. Even if I set explicitly the port, it listening to port

  1. This is the output of the console:
C:\>"C:\Users\...\dnx.exe" -p C:\Users\src\myproject "web" --port 5300
Hosting environment: Production
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.

I can add a new command to project.json, with server.urls parameter and aspnet_env parameter. But I don't know if this is the solution.

@singlewind.
if I run the api using "IIS express" option, and I capture the SystemEnvironment.CommanLine, I see the that the command line looks like I wrote earlier [using --appbase and using applicationhost]

But if I run the "web" command, the command line looks like the later code.

@YehudahA, If you run iisexpress, I assume you were debugging in VS, by default, VS set ASPNET_ENV to Development. If you run web command, it falls back to Production. Is this case affect application conditionally running different code.

I am still experiencing this issue as well. Has any progress been made towards addressing this? See related issue #1368.

You can run webapi in IIS express and keep it open at background by using following command from developer console. "dotnet run" , make sure you run it from same folder in which your project file resides.

@najoshi83 that command doesn't run IIS - it runs locally hosted. Has anyone figured out how to get IISExpress command line working? I need it because JWT Bearer Authentication doesn't work with Kestrel self hosted, and VS Tooling for F# in an ASP.NET Core project is not there yet. VS Code + CLI is what we need to use, but for the IISExpress issue.

This issue is being closed because it has not been updated in 3 months.

We apologize if this causes any inconvenience. We ask that if you are still encountering this issue, please log a new issue with updated information and we will investigate.

@singlewind I was experiencing this same problem and your comment gave me the idea to look into the environment variables for the process using process explorer. Turns out LAUNCHER_ARGS and LAUNCHER_PATH must be set. There's a blog post covering this: https://blog.lextudio.com/how-visual-studio-launches-iis-express-to-debug-asp-net-core-apps-d7fd3677e3c3

So in fact Visual Studio silently adds the two environment variables when launching IIS Express, so that ASP.NET Core related bits can be injected. 

    LAUNCHER_ARGS: -debug -p “C:\Program Files\dotnet\dotnet.exe” -a “exec \”C:\Users\lextm\documents\visual studio 2017\Projects\WebApplication2\WebApplication2\bin\Debug\netcoreapp1.0\WebApplication2.dll\”” -pidFile “C:\Users\lextm\AppData\Local\Temp\2\tmpFD6D.tmp” -wd “C:\Users\lextm\documents\visual studio 2017\Projects\WebApplication2\WebApplication2”
    LAUNCHER_PATH: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\Extensions\Microsoft\Web Tools\ProjectSystem\VSIISExeLauncher.exe

This is a little out of date since now VS creates a temporary file with the arguments and sets LAUNCHER_ARGS="-argFile $USER\AppData\Local\Temp\tmp4460.tmp" which contains something like the above.

Using this I was able to get the api launching properly.
-p should be your process exe
-env contains a bunch of flags such as ASPNETCORE_ENVIRONMENT=Development and others.
Since this seems to change and is internal, I'd recommend just looking in Process Explorer and seeing what the arguments are for your version of visual studio.

@davidmi Glad you figure out. The .NET core tooling now improves a lot. Since docker is getting popular. Why not forget IIS and windows? I quarantine a better performance if you use .NET Core + Alpine container.

Was this page helpful?
0 / 5 - 0 ratings