4

I want my project to start on a particular port using both IIS Express and Kestrel in Visual Studio, using the 'IIS Express' or 'web' start button.

By default, the launchSettings.json file contains a specific port number for IIS Express. However, Kestrel is always started on the default port 5000. How can I get Kestrel to also start on the same port as IIS Express?

launchSettings.json

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:5020/",
      "sslPort": 44320
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "Hosting:Environment": "Development"
      }
    },
    "web": {
      "commandName": "web",
      "environmentVariables": {
        "Hosting:Environment": "Development"
      }
    }
  }
}

project.json Extract

{
    ...
    "commands": {
        "web": "Microsoft.AspNet.Server.Kestrel"
    },
    ...
}

I have tried changing the web command in project.json to:

"web": "Microsoft.AspNet.Server.Kestrel  --server.urls http://localhost:5020"

However, this completely stops the site starting in IIS Express.

Muhammad Rehan Saeed
  • 35,627
  • 39
  • 202
  • 311
  • 1
    Try to use `hosting.json`. See [the answer](http://stackoverflow.com/a/34221690/315935). – Oleg Apr 20 '16 at 09:42
  • 1
    I'm doing something very similar to what you tried [here](https://github.com/joeaudette/cloudscribe.SimpleContent/blob/master/src/example.WebApp/project.json) and [here](https://github.com/joeaudette/cloudscribe.SimpleContent/blob/master/src/example.WebApp/Properties/launchSettings.json) and it works for me. iis uses port 60000 and my custom port-tenants command launches 2 instances on different ports but one of them is the same 60000 as IIS. But both cannot run at once I have to kill IIS express to use the command or kill the command to use IIS. I remember issues at first but reboot fixed it. – Joe Audette Apr 20 '16 at 14:16
  • 2
    This will work better in RC2. In RC1 IIS would provide a dynamic address _in addition to_ kestrel's configured address. In RC2 IIS will _replace_ kestrel's configured address and avoid conflicts. – Tratcher Apr 20 '16 at 17:06

0 Answers0