How can I change IIS Express port for a site

后端 未结 12 1433
死守一世寂寞
死守一世寂寞 2020-11-29 02:32

I want to change the port number on which my website runs while debugging from Visual Studio. I am using Visual Studio 2012, and I am using ASP.NET MVC 4 for my projects I w

12条回答
  •  温柔的废话
    2020-11-29 03:01

    Here's a more manual method that works both for Website projects and Web Application projects. (you can't change the project URL from within Visual Studio for Website projects.)

    Web Application projects

    1. In Solution Explorer, right-click the project and click Unload Project.

    2. Navigate to the IIS Express ApplicationHost.config file. By default, this file is located in:

      %userprofile%\Documents\IISExpress\config

      In recent Visual Studio versions and Web Application projects, this file is in the solution folder under [Solution Dir]\.vs\config\applicationhost.config (note the .vs folder is a hidden item)

    3. Open the ApplicationHost.config file in a text editor. In the section, search for your site's name. In the section of your site, you will see an element like this:

      Change the port number (56422 in the above example) to anything you want. e.g.:

      Bonus: You can even bind to a different host name and do cool things like:

      and then map mysite.dev to 127.0.0.1 in your hosts file, and then open your website from "http://mysite.dev"

    4. In Solution Explorer, right-click the the project and click Reload Project.

    5. In Solution Explorer, right-click the the project and select Properties.

      • Select the Web tab.

      • In the Servers section, under Use Local IIS Web server, in the Project URL box enter a URL to match the hostname and port you entered in the ApplicationHost.config file from before.

      • To the right of the Project URL box, click Create Virtual Directory. If you see a success message, then you've done the steps correctly.

      • In the File menu, click Save Selected Items.

    Website projects

    1. In Solution Explorer, right-click the project name and then click Remove or Delete; don't worry, this removes the project from your solution, but does not delete the corresponding files on disk.

    2. Follow step 2 from above for Web Application projects.

    3. In Solution Explorer, right-click the solution, select Add, and then select Existing Web Site.... In the Add Existing Web Site dialog box, make sure that the Local IIS tab is selected. Under IIS Express Sites, select the site for which you have changed the port number, then click OK.

    Now you can access your website from your new hostname/port.

提交回复
热议问题