How can I change IIS Express port for a site
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
.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.
To specify a port for a Web application project that uses IIS Express
In Solution Explorer, right-click the name of the application and then select Properties. Click the Web tab.
In the Servers section, under Use Local IIS Web server, in the Project URL box change the port number.
To the right of the Project URL box, click Create Virtual Directory, and then click OK.
In the File menu, click Save Selected Items.
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).
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
In Solution Explorer, right-click the project and click Unload Project.
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)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
to127.0.0.1
in yourhosts
file, and then open your website from "http://mysite.dev"In Solution Explorer, right-click the the project and click Reload Project.
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
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.
Follow step 2 from above for Web Application projects.
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.