One of the questions I'm often asked is how to set the default port for a File System web in Visual Studio 2005.
New is Visual Studio 2005 is a built in development web server for testing the web applications your developing with out having IIS installed on the dev machine. The server is named WebDev.WebServer.exe. It gets installed by VS into the Framework version directory. If you run this application without any argument you will get this usage screen.

When you create a new website in VS 2005, you pick how the site will be accessed, for example it can be a File System, HTTP, or FTP site.
If you pick File System, this will tell VS that it should use WebDev.WebServer.exe to serve up the application. You’ll notice that one of the command line arguments for WebDev.WebServer.exe is /port: , yet at no time was the user prompted for a port number. What port is it using and how can I override that setting?
VS 2005 is dynamically getting the next avail ephemeral port on the machine. This is done via a call the WinSock API.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/bind_2.asp
"For TCP/IP, if the port is specified as zero, the service provider assigns a unique port to the application with a value between 1024 and 5000."
btw: It is possible to get a automatically assigned port larger than 5000 by changing MaxUserPort under HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
http://www.microsoft.com/resources/documentation/Windows/2000/server/reskit/en-us/Default.asp?url=/resources/documentation/Windows/2000/server/reskit/en-us/regentry/58791.
VS will store the dynamically computed port in the solution file and reuse it each time the website is opened with that solution. Even though VS has stored this port in the solution file, it’s possible that VS with change the port again when launching WebDev.WebServer.exe if that port is in use by a different application. Fortunately VS is smart enough to not dynamically change the port if you have another project in the same solution with a Web Reference to that Website project. Generally speaking the developer should not have to worry about these dynamically assigned ports.
However, what if the other application is not in the same solution and you just want to fix the port used and never have it changed by VS. How can you do this?
Once you’ve opened a File System Web you can change how VS assigns port numbers. To do this select the root node of your site, and press F4 to bring up the properties tool window. Within this window you’ll see a category of parameters for the Development Web Server. Change the “Use dynamic ports” to False then set the port number to any value you like.
Btw: you’ll notice that the dynamic port assigned in this example is 12988, well beyond the 5000 limit we’d expect. That is because on the machine I used MaxUserPort was set to 65534.
Now in this example I’ve change the dynamic port to False and set the port number to 8080.
These settings will be persisted in the solution file and never changed by VS. Be aware that if you add the same website to a different solution it will default to using a dynamic port when run in that solution. These settings are specific to the solution containing that website.
I’d like to call attention to one other issue that can happen when calling Web Services hosted by WebDev.WebServer.exe. If NTLM authentication is enabled for WebDev.WebServer.exe, you may need to manually set UseDefaultCredentials = True in the client proxy.
You can check the NTLM setting in the project properties, Start Options.
If set, you may need to set the UseDefaultCredentials property to True in the client proxy calling that service. This should have been automatically added to the proxy during code generation but if you’re getting a “401 Authentication failed” error then you’ll need to set this property when calling a web service hosted by WebDev.WebServer.
Dim ls As New localhost.Service
ls.UseDefaultCredentials = True
MsgBox(ls.HelloWorld())
As you can see there are a number of ways to change how VS launches WebDev.WebServer.exe. By default you should not have to change anything but if you need to, you can.
Hope, this helps,
Brad