How can I change IIS Express port for a site

2019-01-06 14:36发布

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 want to change the port. Random port or fixed anyone will work just want to change the port.

8条回答
该账号已被封号
2楼-- · 2019-01-06 14:42

Edit .sln file using an editor like notepad.

Replace All Ports With New Port.

查看更多
贪生不怕死
3楼-- · 2019-01-06 14:42

Deploy your application in the IIS with default port. Try to debug it using visual studio.It's good practice.if you use visual studio,It will keep changing the port number most of the time.So better deploy the application in the IIS first and Open the same in visual studio and Debug it.

查看更多
够拽才男人
4楼-- · 2019-01-06 14:43

You can first start IIS express from command line and give it a port with /port:port-number see other options.

查看更多
贼婆χ
5楼-- · 2019-01-06 14:51

Another fix for those who have IIS Installed:

Create a path on the IIS Server, and allocate your website/app there.

Go to propieties of the solution of the explorer, then in front of using the iisexpress from visual studio, make that vs uses your personal own IIS.

Solution Proprieties

查看更多
6楼-- · 2019-01-06 14:53

Right click on your MVC Project. Go to Properties. Go to the Web tab.
Change the port number in the Project Url. Example. localhost:50645
Changing the bold number, 50645, to anything else will change the port the site runs under.
Press the Create Virtual Directory button to complete the process.

See also: http://msdn.microsoft.com/en-us/library/ms178109.ASPX

Image shows the web tab of an MVC Project enter image description here

查看更多
聊天终结者
7楼-- · 2019-01-06 14:56

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.)

To specify a port for any web project that uses IIS Express:

  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. Navigate to the IIS Express ApplicationHost.config file. By default, this file is located in:

    %userprofile%\Documents\IISExpress\config

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

    <binding protocol="http" bindingInformation="*:56422:localhost" />

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

    <binding protocol="http" bindingInformation="*:44444:localhost" />

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

    <binding protocol="http" bindingInformation="*:80:mysite.dev" />

    and then map mysite.dev to 127.0.0.1 in your hosts file, and then open your website from "http://mysite.dev"; but that's outside the scope of this answer so I won't go into any more details)

  4. If you had a Website project:

    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.

    If you had a Web Application project:

    In Solution Explorer, right-click the solution, select Add, and then select Existing Project..., browse to and select your web application's project file. Then:

    • In Solution Explorer, right-click the name of the project and then select Properties. Click 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, and then click OK.

    • In the File menu, click Save Selected Items.

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

查看更多
登录 后发表回答