I've noticed that Visual Studio like to change the port used for my application from time to time, and I was wondering why. After some Stack Overflow reading, I've found solutions to prevent this (it is possible to assign a static port). However, I do not find it to be a problem (merely a curiosity) and do not need to a assign a static port. I just want to know why it does that.
While debugging my application, VS will run on one port. On another run 5 or ten minutes later, it will run on an entirely different port. As far as I know, no other processes on my machine are using these same ports, so why the change? Once it finds an available port, why does it not continue to use it?
This is by design. Either you can have random ports every time, or you can assign a fixed one per project. Keeps things simple I guess (rather than figuring out if the previously used port is taken or not and then based on that, use the old one or a new one)!
As Mrchief said, this is by design. You can opt to use IIS by creating a virtual directory and making the appropriate selection on the Web tab of the project properties.
Then your URL (can debug also) will look like:
http://localhost/myproject
Port 80 will now be the default :)
Related
I am using VS2015 and I am trying to run a website application, but every time I run the project I can't load the IISExpress because it says that the port 80 is in use, I run the Tcpview.exe from SysInternals to see who was using the port, but seems not to be in use. I found some related threads saying that can be a problem with the antivirus, I am using Symantec.
Here are the properties of the project, as you can see I tried to change the port manually, but it didn't worked
See the picture below
It is something weird, if the website is inside a solution, seems that it doesn't load correctly the application and all the time the port is ins use. I solved it using this approach
https://stackoverflow.com/a/34309702/7019416
I just loaded directly using the Visual Studio Option-> Open-> Website and removing the entries from that the post below advice
I'm using Microsoft Visual Studio 2010, developing and debugging a ASP.NET C# application.
(I would imagine that other versions of Visual Studio might also have this issue, hence the additional tags.)
During debugging I find it easier to set the Start URL (in the project's Properties tab) to
http://localhost:[port]/Account/Login
where [port] is the port that the development server opens when it is created.
This [port], however, is the issue; as the development server can potentially not work/stop working from time to time, and can occasionally re-assign to a different localhost port, setting the start page as above - basically a static address - means extra work having to either alter the URL in the debugging browser window, or going into the properties page of the solution and changing the port number prior to debugging.
Admittedly, its not much extra work, and it might be a case of laziness, but its not really necessary when there might be potential for a dynamic alternative that I'm not aware of. The use of visual studio's built-in development server is preferred over setting up a dedicated static server simply for speed of setting up a project and for brief stints of development debugging of new code additions.
In an ideal world and/or for longer QA debugging, I'd publish to a dedicated debug server, but that would be for a nearly finished project in its entirety or major milestones.
Is there any way of setting a relative/dynamic port as part of the start page in a solution's properties page, or will I just have to keep changing the port manually?
To my knowledge there is no way to scope the ports VS/IIS Express will use for running the dev server. I have never heard of a work around of killing the dev server when it locks up - I just close/stop the server from the toolbar.
The dev server should only lock up occasionally. If it's frequent then I would look into other causes or what you were referring to and stand up a full blown dev IIS server, but like you said, that takes a bit more time.
I have created a site with webmatrix. When I try to run it, it says it cannot because it needs admin right to make the connection to port.
I tried to run Webmatrix with admin right it doesn't change anything. What should I do ?
Your question is a bit hard to understand. But I assume you are trying to connect to the site externally meaning from a different computer than the one running webMatrix. If so, there are a couple of things to get right and this post by Vaidy will help you: Serving external traffic with WebMatrix
First thing is that you need to be sure that the port you want to use not used by any application.
the problem is that many time user want to debug application in VS oR VWD and Webmatix. because they use same port so Webmatix not run because VWD already use them.
well first thing is that try to change the port and run if that's not work then they need to run as administator for doing that:-
select webmatix icon open the propety go to advanced and choose tor run as administration.
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.
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:
(source: scottgu.com)
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.
Open your project
Click (not right click) on the name of the project in the solution explorer (that top, bolded line)
Hit f4 - this will bring up a properties panel
Change "Use dynamic ports" to False
Optionally change the Port number to whatever port you want to use
And you're done.
This port number is initially assigned randomly, but Visual Studio will try to use that same port number every time the application starts.
Check out the Properties of your web application in solution explorer (Right click > Properties)
The web tab is the one you are looking for.
Kindness,
Dan
I've been using the macro from this blog entry for attaching the Visual Studio debugger to an already running instance of the Web Application I'm currently working on. However, if I have more than one instance of the Visual Studio web server running it's pot luck which one it'll attach to.
Is there a way to determine what port is configured in the Web project so I can modify the macro to filter its choice of process to that one?
Further Info
I'm aware that you can set the port number to a static one - I've done just that from the get-go, what I'm trying to determine is how to programatically determine the defined port-number so I can modify the macro (in the linked blog entry) and ensure it connects to the right instance of the Visual Studio web server.
The way I have things running is I have two (or more) instances of Visual Studio running, each of which contains a Solution, which contains a web project and one or more other projects - typically an Installer project), so when I trigger the macro from a given instance of Visual Studio, I want to find the Web Project within that instances loaded solution and determine the port it's running against.
This code will get you a list of all ports for the projects in the current solution:
Sub GetWebProjectPorts()
Dim ports As String
For Each prj As Project In DTE.Solution.Projects
For Each p As EnvDTE.Property In prj.Properties
If p.Name.Contains("DevelopmentServerPort") Then
If Not String.IsNullOrEmpty(ports) Then
ports += ","
End If
ports += p.Value.ToString()
End If
Next
Next
MsgBox(ports)
End Sub
If that can help you, I have found a link that might actually to the trick.
However, it require DllImport call and a lot of fun.
You can take a look at that article there: http://bytes.com/forum/thread574901.html
Quotes from the actual site:
By calling into iphlpapi.dll using
PInvoke interop. Google around for
GetExtendedTcpTable and iphlpapi.dll,
I'm sure you will find some existing
stuff.
Willy.
And one last:
Here are some API-Methods for my
purposes:
GetTcpTable()
AllocateAndGetTcpExTableFromStack()
GetExtendedTcpTable()
I wrote a small programm that is able
to show me all Processes with the
belonging TCP-Ports (with
AllocateAndGetTcpExTableFromStack())
running under Windows XP.
Now my problem is, that under Windows
2000 I can't use
AllocateAndGetTcpExTableFromStack() or
GetExtendedTcpTable() so I'm only able
to use GetTcpTable() to list all
TCP-Ports but without the belonging
processes.
Did somebody have the same problem or
is there another way (.Net or WMI
etc.) to solve my problem?
Thanks in advance,
Werner
If you go to the properties for your web project and look under the "Web" tab, you can specify which port the project will always start up on. Then you can click "Enable Edit and Continue" so you don't have to stop debugging and restart continuously.