Assign a static port to Website

by Vahid 15. December 2009 08:04
A while ago in a project we had the requirement to assign a static port number to our website project. The very first thing came to my mind was that we just can assign static port number to web application project type and we cannot assign a static port to web site project. Anyway I started searching in the internet for a solution to make sure about it. I spent quit a long time looking for an answer but I could not find any almost everywhere it was mentioned that we cannot assign a static port to a website and it is constrained to use dynamic port.I was convinced at the time and we managed to convert to web application. Surprisingly recently a friend of mine, Ali, referred a perfect solution for this issue to me and I thought it’s worth sharing with you. Step 1- the very first step is to add the Web Server external tool to Visual Studio. To do so
  • go to the Tool menu
  • Click on the External Tool menu


Step 2- next step is to actually adding the external tool. Once the external tool window is open, click on Add button and
  • In the title text box give your web server a name (in this case I have called it webserver 1919).
  • In the command text box enter your .net web server address (in my computer it is C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\WebDev.WebServer.EXE)
  • In the Arguments text box enter /port:{port number} /path:$(ProjectDir) where {port number} is your desired static port number (in this case I have chosen port 1919 and the value is “/port:1919 /path:$(ProjectDir)”).
  • Tick use output window check box
  • Click on the Ok button


Step 3- now that the external tool is added and ready to use you have to change your website project setting to use this web service rather than default web service. To do so
  • Right click on your project file and click on the Property Pages menu.
  • On the left side of the property window click on Start Options.
  • In the Server section choose Use custom server
  • In the base URL text box enter http://localhost:1919 where 1919 should be the port number you have chosen in step 2
  • Click on the Ok button


Step 4- the last step is to start the custom web server before debugging the application. To do so:
  • Click on the Tool menu. Now a new menu item having the name you have assigned to the customer web server in step 2 should be displayed in the tool menu.
  • Click on the new menu item (in this case webserver 1919)

Now you are ready to go. Click F5 and start debugging your web site on a static port.