Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Visual Studio decide which port to run applications on?

When you run an application from within visual studio, it seems to pick a random port on localhost. For example, running an application right now, I get

http://localhost:3240/ApplicationStuffHere

I realize this port gets loaded into the solution file, via

VWDPort = "3240"

How does this get decided on? it seems fairly random.

like image 598
Chris Avatar asked Sep 09 '09 13:09

Chris


People also ask

How do I choose a port for my application?

Choose a default port that doesn't interfere with the most common daemons and servers. Also make sure that the port number isn't listed as an attack vector for some virus -- some companies have strict policies where they block such ports no matter what. Last but not least, make sure the port number is configurable.

How do I change the port number of a .NET application?

In Solution Explorer, click the name of the application. In the Properties pane, click the down-arrow beside Use dynamic ports and select False from the dropdown list. This will enable editing of the Port number property. In the Properties pane, click the text box beside Port number and type in a port number.


2 Answers

By default, ASP.NET Web Application Projects are configured to launch and run using the built-in VS Web Server (aka Cassini) on a random HTTP port on the machine.

This port number can be changed if this port is already in use, or if you want to specifically test and run using a different number:

alt text
(source: scottgu.com)

like image 66
rahul Avatar answered Sep 23 '22 23:09

rahul


I know this is a little bit old, but I was wondering the same thing. I eventually found the answer for VS2005, but figured I'd share it with the stack overflow community.

  1. Open your project
  2. Click (not right click) on the name of the project in the solution explorer (that top, bolded line)
  3. Hit f4 - this will bring up a properties panel
  4. Change "Use dynamic ports" to False
  5. Optionally change the Port number to whatever port you want to use

And you're done.

like image 26
Ryan Kinal Avatar answered Sep 22 '22 23:09

Ryan Kinal