localhost port is changing in Visual Studio 2017
The port may be changing because launchSettings.json
is ignored by source control. This common gitignore file, for example, excludes:
**/Properties/launchSettings.json
Visual Studio 2017 stores ASP.NET Core server settings (for both IIS Express and Kestrel) in this file. If it's ignored by source control, it will be regenerated on each machine with a random port. If you check the file in, every machine will use the same server settings.
How do I change the debug port in Visual Studio 2017?
For me, I was able to find it with the following steps in Visual Studio 2017:
- Right click on the web project, then click Properties.
- Click on the Debug tab.
- Under the Profile IIS Express, you will find the port at the App URL box.
How can I change IIS Express port for a site
To specify a port for a Web application project that uses IIS Express
In Solution Explorer, right-click the name of the application and then select Properties.
Click the Web tab.In the Servers section, under Use Local IIS Web server, in the Project URL box change the port number.
To the right of the Project URL box, click Create Virtual Directory, and then click OK.
In the File menu, click Save Selected Items.
To verify the change, press CTRL+F5 to run the project.
The new port number appears in the address bar of the browser.
From How to: Specify a Port for the Development Server (archive.org backup here).
Why aren't my networked computers able to access localhost from VS2017?
I was able to solve this problem by changing the binding values in
applicationhost.config
- VS2015 onwards, it can be found inside the individual project folder
%ProjectFolder%/.vs/config/
- In pre-2015 VS, its available in
%USER%/Documents/IISExpress/config/
If you are familar with XAMPP, the setting is similar to %XAMPP%/apache/conf/httpd.conf
- The difference is that, instead of setting a Listen port number, you have to properly bind the port in IISExpress
- By default, port is bound to localhost for the host computer. Say, port 3940 is bound as
*:3940:locahost
, which makes it only available to the computer running VS. - To make this available to networked computers, you need to change this section as follows:
<bindings>
<binding protocol="http" bindingInformation="*:3940:localhost" />
</bindings>
to:<bindings>
<binding protocol="http" bindingInformation="*:3940:*" />
</bindings>
- Note: In some cases,
bindingInformation="*:3940:"
may be used instead ofbindingInformation="*:3940:*"
If after all this, it still does not work, then it may be a firewall issue as @Mukesh pointed out in his comment.
- Firewall issues can be quickly found out by simply pinging the target device.
- If the ping is successful but the port is not allowed, then open the firewall in advanced mode
- Open RUN (Windows + R)
- Type firewall.cpl
- Click on Advanced Settings
- Click on Inbound Rules
- Create New Rule
- Add your desired port to the rule
- Port > Specific local ports:
3940
> Allow the connection > Check all (Domain, Private, Public) > Give a name to your rule:ExampleRule
> Finish- You can replace
3940
with your desired port number or port range. It is also possible to select all possible ports.- optional: Although nothing really needs to be done in the client computer, you may need to configure your firewall inbound rule to accept all Inbound connections
- If it is not a firewall issue, it can be something else entirely. Maybe you're getting a 400 Error page, or a 503 Error. The following SO questions helped me a lot to tackle those problems (although I had to revert the ACL allowance later). I hope this is useful to someone in the future
- IIS Express Configuration
- Change binding, ACL and Port forwarding
- HTTP 400 Bad Request Error
- Solution to this ^ is here
- 503 Service Unavailable Error
- Sometimes this is solved by simply creating binding entries in
applicationhost.config
- Other times, its the duplicate-binding problem. And you need to remove a binding entry during those times. If you are editing
applicationhost.config
inside the project folder, then it is okay to keep only one site and binding information.- for my particular case, I had to revert this operation
netsh http add urlacl url=http://192.168.10.3:3940/ user=everyone
with thisnetsh http delete urlacl url=http://192.168.10.3:3940/
because I kept getting 502 Bad Gateway error when I tried tunneling.- Things to remember:
- Please remember to properly restart IISExpress after each change. Normally VS does this by itself. Just double check for any running instances.
- Also, always run VS in administrative mode. This usually clears many problems and also allows all sub-processes, such as IISExpress to startup in elevated privilege mode to avoid permission errors.
Visual studio 2017 "Unable to connect to web server 'IIS Express'"
I installed core 2.0 and updated VS 2017 to 15.4.3 today, had the same error.
I ended up changing the application to run on a different port, it worked for me.
I have tried to delete the vs folder but did not work.
Hope it helps.
Related Topics
How to Pass Parameter from @Url.Action to Controller Function
What Could Cause an Assignment to Not Work
How to Generate Getters and Setters in Visual Studio
Deserialize Json in C# - How to Handle Null Return Values
How to Submit Disabled Input in ASP.NET MVC
How to Download a File from a Url in C#
Using Linq to Groupby and Sum Datatable
How to Provide Success Messages ASP.NET MVC
Split a Comma-Separated String With Both Quoted and Unquoted Strings
How to Hide a Property in Webapi
How to Read Request Body in an ASP.NET Core Webapi Controller
Passing a List of Objects into an MVC Controller Method Using Jquery Ajax
Using Enum and | as Dictionary Key
Validate Indian Phone Number With Optional +91 or 0 Preceeding 10 Digits
How to Perform Join Between Multiple Tables in Linq Lambda
Localhost Port Is Changing in Visual Studio 2017
Save Byte[] into a SQL Server Database from C#
Setting Connection String With Username and Password in Asp.Core MVC