How can I change IIS Express port for a site

207,834

Solution 1

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. Click the Web tab.

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

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

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

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

From How to: Specify a Port for the Development Server (archive.org backup here).

Solution 2

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 <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"

  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.

Solution 3

.Net Core

For those who got here looking for this configuration in .Net core this resides in the Properties\lauchSettings.json. Just edit the port in the property "applicationUrl".

The file should look something like this:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:53950/", //Here
      "sslPort": 0
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "index.html",
      "environmentVariables": {
        "Hosting:Environment": "Development"
      },
    }
  }
}

Or you can use the GUI by double clicking in the "Properties" of your project.

Note: I had to reopen VS to make it work.

Solution 4

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

Solution 5

If you just want to change the port because it is already in use. Follow the following steps.

In Visual studio

  1. Right-click on Project Node and select Unload Project
  2. Right-click on Project Node and Edit .csproj file.
  3. Search for the following tags and remove them
<DevelopmentServerPort>62140</DevelopmentServerPort>
<DevelopmentServerVPath></DevelopmentServerVPath>
<IISUrl>http://localhost:62116/</IISUrl>
  1. press Ctrl + S to save the document
  2. Right-click on Project Node and load Project

It will work by selecting another port randomly.

For further information. please click

Share:
207,834
Mohit
Author by

Mohit

Updated on September 12, 2021

Comments

  • Mohit
    Mohit over 2 years

    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.

  • Mohit
    Mohit over 9 years
    Dear Mark, I don't think you had read the question carefully!
  • hobwell
    hobwell over 9 years
    Awesome, exactly what was needed. Had to fish around for a working port, but this did the trick, thank you.
  • Dirk Strauss
    Dirk Strauss over 8 years
    Thanks Saeb. This works perfectly. Just a point to note... I am using source control and after adding my Website project back I had to go to File > Source Control > Advanced > Change Source Control and rebind my project to my source control server. This just meant selecting the project in the list and clicking on the 'Bind' button next to 'Refresh'. Thanks for the excellent answer.
  • Itanex
    Itanex over 8 years
    Additionally, it is not a good practice to develop directly against IIS. This MSDN article explains when you should use IISExpress, IIS, or an External Server when developing. msdn.microsoft.com/en-us/library/58wxa9w5(v=vs.120).aspx
  • Supersharp
    Supersharp about 8 years
    That doesn't work for Web Sites. Only for Web Application projects.
  • Paul Gorbas
    Paul Gorbas about 8 years
    Great answer - Instead of "right-click the project name and then click Remove or Delete", you can select "unload project instead", then again edit your applicationhost.config, mine was at "<path to my solution (.sln)file>\.vs\config\applicationhost.config" (note the .vs folder is a hidden item, so select the option to show hidden files in you file explorer )
  • Saeb Amini
    Saeb Amini about 8 years
    @PaulGorbas glad it helped you. Note that you can't "unload" websites, that only works for web applications.
  • MiloDC
    MiloDC over 7 years
    How to make this work for a custom SSL port? For any port except 60233, I get "This page can’t be displayed" in Internet Explorer, and similar messages in other web browsers. Where in Windows 7 does one designate SSL ports?
  • calcazar
    calcazar over 7 years
    No Web tab here... You would think that in 2017, this would no longer be an issue.. That or at the very least we should be able to change ports without having to do magic
  • Auguste Van Nieuwenhuyzen
    Auguste Van Nieuwenhuyzen about 7 years
    Thanks! Though %systemdrive%\Users\<YourWindowsUsername>\Documents isn't necessarily correct - it's the path to your 'My Documents' folder, which I've got on a different drive to my users folder. And there doesn't appear to be a variable set to that in Windows.
  • KingRider
    KingRider almost 7 years
    Visual Studio 2015 not exist option (ASP.NET Empty Web Site) .. how to make?
  • silkfire
    silkfire almost 7 years
    Brilliant answer. Restarting VS worked for me. Apparently BitDefender's ProductAgentService.exe service uses port 50151 which conflicted with IIS Express' default port.
  • qxotk
    qxotk about 6 years
    @IanGrainger the path above is: %userprofile%\Documents\IISExpress\config - this is different from what you mention - I just tested and it put me in the right place.
  • qxotk
    qxotk about 6 years
    This fix worked for me, but I had to mess around quite a bit to get iisexpress to run, as I was getting errors within vs2017. This page shows how to run iisexpress from command line, which was helpful for me: docs.microsoft.com/en-us/iis/extensions/using-iis-express/…
  • qxotk
    qxotk about 6 years
    NOTE: In order for "Add Existing Website" to work in vs2017 - you should have a version of at least 15.6.5 - as there were some earlier versions where add existing website was not working at all.
  • Rod
    Rod almost 6 years
    I had been doing all of this, except clicking the Create Virtual Directory button. Doing that made the different; now it works. But why is that necessary?
  • VladT
    VladT almost 6 years
    Well if you do this, you are no longer using IIS Express, but local IIS. So just go to Web tab in Project Properties and edit the port to whatever you need.
  • fletchsod
    fletchsod over 4 years
    Why local IIS instead of IIS express?
  • FatAlbert
    FatAlbert over 4 years
    SSL ports are restricted to 44300-44399. Could be good to know.
  • Brad Irby
    Brad Irby almost 4 years
    This is a valid solution if you are using the old style Web Site Project (i.e. for ASP Classic files) in VS2019. You must edit the solution file because there are no other property pages. My project looks like this in the sln file. Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "MyWebSitePrj", "localhost:50194", "{BC30BA4B-1D1D-48D0-B1E8-86CBD64611B5}"
  • Red_Phoenix
    Red_Phoenix almost 2 years
    Just what I was looking for. Thank you. (on VS 2022 BTW)