14

I'm using IIS Express to host my website and API both of which are ASP.NET Core apps. When I look at my HTTP network logs using Fiddler, I always forget what port belongs to which app. To solve this, I would like to change the port number that my apps currently use to a number that is more memorable.

For example, I want my UI website to use port 50000 and my internal API to use 50001.

Intuition tells me to change the "sslPort" and "launchUrl" to 50000 and 50001 respectively but that doesn't work.

For example, this is my current launchSettings.json file for my ASP.NET

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iis": {
      "applicationUrl": "http://localhost",
      "sslPort": 0
    },
    "iisExpress": {
      "applicationUrl": "http://localhost:29751",
      "sslPort": 44371
    }
  },
  "profiles": {
    "Development": {
      "commandName": "IISExpress",
      "launchUrl": "https://localhost:44371/"
    }
  }
} 

Changing it to this doesn't work

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iis": {
      "applicationUrl": "http://localhost",
      "sslPort": 0
    },
    "iisExpress": {
      "applicationUrl": "http://localhost:29751",
      "sslPort": 50000
    }
  },
  "profiles": {
    "Development": {
      "commandName": "IISExpress",
      "launchUrl": "https://localhost:50000/"
    }
  }
} 

Question: Why doesn't this change work? How do I change the port number?

Many thanks...

burnt1ce
  • 14,387
  • 33
  • 102
  • 162
  • You need to change the `"applicationUrl"` in the IIS Express settings. – poke Aug 11 '18 at 16:08
  • @Tseng, The question that you marked as a duplicate of (https://stackoverflow.com/questions/40550798/cant-set-the-port-for-net-core-application-in-launchsettings-json) isn't a duplicate. The person asking the question was using "Project" as the launch type while I'm using "IIS Express". – burnt1ce Aug 12 '18 at 12:58
  • @poke. why do I have to change the applicationUrl? I want to change the SSL port and not the unecyrpted port. – burnt1ce Aug 12 '18 at 13:00
  • @Tseng, also, I think that question you referred to is outdated and not applicable. The best answer says "Also you shouldn't directly edit that the launcherSettings.json file and instead use the Project Properties to change stuff.". These settings are not editable in the Project Settings. They might have been back in 2016 but not anymore. – burnt1ce Aug 12 '18 at 13:04
  • Of course they are editable. Project Properties -> Debug -> choose IIS Express from the pull-down. SSL port was never editable via that though. But the answer also tells you where to edit it, if you were to edit it manually: _One reason for this is that if you change it via project properties, Visual Studio will also edit the IIS Express files (located in the `.vs/config/applicationhost.config` folder of your solution)_ – Tseng Aug 12 '18 at 13:22
  • In any case, deleting the `applicationhost.config` should force VS2017 to rebuild it on next start – Tseng Aug 12 '18 at 13:24
  • 2
    I found the solution. When changing the SSL port number, it must be within 44300 - 44399 otherwise it won't work. Reference: https://developercommunity.visualstudio.com/comments/43139/view.html. @Tseng, please remove the "duplicate" flag. – burnt1ce Aug 17 '18 at 02:40
  • @burnt1ce you should post that as an answer to the question – Marcus Höglund Aug 17 '18 at 06:17
  • I'll do that. I wasn't able to post an answer when my question was flagged as a duplicate. – burnt1ce Aug 19 '18 at 13:31

1 Answers1

41

I found the solution. When changing the SSL port number, it must be within 44300 - 44399 otherwise it won't work. Reference: developercommunity.visualstudio.com/comments/43139/view.html. @Tseng, please remove the "duplicate" flag

Alex C
  • 516
  • 7
  • 15
burnt1ce
  • 14,387
  • 33
  • 102
  • 162
  • To elaborate: I closed the solution, opened the .sln file in notepad++, observed the incorrect port # (out of the required range) on lines such as "localhost:59164", replaced six occurrences of 59164 with 44301 (randomly chosen but within the required range), saved the changes, opened the sln in visual studio and everything was fine. IIS Express now worked. – DeveloperDan Jul 12 '19 at 15:04
  • 10
    How is a mere mortal supposed to divine secrets like this? – WernerCD Nov 12 '19 at 21:36
  • 1
    For those who'd like to understand how this range of ports is defined: https://learn.microsoft.com/en-us/iis/extensions/using-iis-express/running-iis-express-without-administrative-privileges#using-ssl ("the IIS Express setup program [...] configures HTTP.SYS to reserve ports 44300 through 44399 for SSL"). – Fabrice Apr 06 '20 at 17:01
  • Even when running VS.NET as admin, I am unable to bind it to port 50000. Oh well, looks like I'll have to make my peace with 44342, then. – Jay Jul 19 '21 at 12:24
  • Thanks so much for this. I've been struggling with this for a while now. The reason this has been so frustrating is because when running a web app with the dotnet CLI, ports are defaulted to 5000/50001. – Adriang Sep 30 '21 at 18:34