Export (0) Print
Expand All

How to: Specify a Port for the Development Server

In Visual Studio, you can select from several Web servers: IIS, IIS Express, or the built-in Visual Studio Development Server. For information about the differences between these servers, see Web Servers in Visual Studio for ASP.NET Web Projects.

By default, when you create a Web site or a Web application project in Visual Studio that uses IIS Express or the Visual Studio Development Server, a port is selected for the project. For example, if you are testing a page named MyPage.aspx, when you run the page using IIS Express or the Visual Studio Development Server, the URL of the page might be the following:

http://localhost:31544/MyPage.aspx

If you want to run the project on a specific port, you can configure the Web server to do so.

NoteNote

Visual Studio cannot guarantee that the port you specify will be available when you run your file-system Web site. If the port is in use when you run a page, Visual Studio displays an error message.

To specify a port for a Web site project that uses IIS Express

  1. In the Tools menu, select Options and then General.

  2. Make sure the Always Show Solution option is selected.

  3. In Solution Explorer, right-click the project name and then click Remove. This removes the project from your solution, but does not delete the corresponding files on disk.

  4. Click OK.

  5. In Windows Explorer, navigate to the IIS Express ApplicationHost.config file. By default, this is located in the following folder:

    %systemdrive%:\Users\<username>\Documents\IISExpress\config

  6. Open the ApplicationHost.config file in a text editor such as Notepad. In the sites section, search for the Web site name.

  7. In the bindings section for the Web site, change the port binding.

    The following example shows the bound port set to 40955.

    
    <site name="WebSite1" id="1">
       <application path="/" applicationPool="Clr4IntegratedAppPool">
          <virtualDirectory path="/" physicalPath="C:\WebSites\WebSite1" />
       </application>
       <bindings>
          <binding protocol="http" bindingInformation="*:40955:localhost" />
       </bindings>
    </site>
    
    
  8. Save the ApplicationHost.config file and close the text editor.

  9. In Solution Explorer, right-click the solution, select Add, and then select Existing Web Site.

  10. In the Add Existing Web Site dialog box, make sure that the Local IIS tab is selected.

  11. Under IIS Express Sites, select the site for which you have changed the port number, and then click Open.

    The project name contains the URL with the new port number for the Web site (for example, http://localhost:40955/). If the solution was created at the same time as the original Web site project, the previous port number will still be part of the solution name (for example, localhost_40954).

  12. To update the solution name to reflect the new port number, in Solution Explorer right-click the solution name, select Rename, and then specify a new name.

  13. On the File menu, click Save All.

  14. To verify the change, press CTRL+F5 to run the project.

    The new port number appears in the address bar of the browser.

To specify a port for a Web site project that uses the Visual Studio Development Server

  1. In Solution Explorer, select the project name.

  2. In the Properties pane, set Use dynamic ports to False.

    This enables editing of the Port number property.

  3. Enter a port number for the Port number property.

  4. Click outside of the Properties pane. This saves the property settings

  5. To verify the change, press CTRL+F5 to run the project. The new port number appears in the address bar of the browser.

To specify a port for a Web application project that uses IIS Express

  1. In Solution Explorer, right-click the name of the application and then select Properties.

  2. Click the Web tab.

  3. In the Servers section, under Use Local IIS Web server, in the Project URL box change the port number.

  4. To the right of the Project URL box, click Create Virtual Directory, and then click OK.

  5. In the File menu, click Save Selected Items.

  6. To verify the change, press CTRL+F5 to run the project.

    The new port number appears in the address bar of the browser.

To specify a port for a Web application project that uses the Visual Studio Development Server

  1. In Solution Explorer, right-click the name of the application, and then select Properties.

  2. Click the Web tab.

  3. In the Servers section, under Use Visual Studio Development Server, select Specific port.

  4. Change the port number.

  5. In the File menu, click Save Selected Items.

  6. To verify the change, press CTRL+F5 to run the project.

    The new port number appears in the address bar of the browser.

Community Additions

ADD
Show:
© 2014 Microsoft