Complete Guide to Changing IIS Express Port in Visual Studio

Nov 23, 2025 · Programming · 9 views · 7.8

Keywords: IIS Express | Port Configuration | Visual Studio | ASP.NET MVC | Development Server

Abstract: This article provides a comprehensive guide on modifying IIS Express port numbers for ASP.NET MVC 4 projects in Visual Studio 2012. It covers two primary methods: project property configuration and manual editing of ApplicationHost.config file, enabling developers to set fixed or random ports flexibly. Additional coverage includes specific configurations for .NET Core projects, with complete operational steps and verification methods.

Project Property Configuration Method

For developers working with ASP.NET MVC in Visual Studio, changing the IIS Express port number is a common requirement. The project properties interface provides the quickest and most recommended approach for port configuration.

Begin by right-clicking the project name in Solution Explorer and selecting "Properties". In the properties window, navigate to the "Web" tab. Within the servers section, locate the "Use Local IIS Web server" option and modify the port number in the "Project URL" text box. The port number can be any valid TCP port, with recommendations suggesting ports between 1024 and 65535 that are not currently in use.

After modifying the port number, click the "Create Virtual Directory" button. The system will automatically generate the corresponding IIS Express configuration, displaying confirmation upon successful operation. Finally, save the changes through the File menu or using the Ctrl+S keyboard shortcut.

To verify the configuration, press Ctrl+F5 to run the project. The browser will automatically open displaying the new URL address containing the modified port number. If the page loads normally and the address bar shows the correct port, the configuration has been successful.

Configuration File Manual Editing Method

Beyond the Visual Studio interface, developers can directly edit the IIS Express configuration file. This method is particularly useful for scenarios requiring finer control or when encountering issues with interface-based configuration.

First, locate the ApplicationHost.config file. In newer Visual Studio versions, this file typically resides in the solution directory under the .vs\config folder. Note that the .vs folder is hidden by default, requiring the display of hidden files to be enabled in file explorer.

Open the ApplicationHost.config file using a text editor and navigate to the corresponding website configuration within the <sites> section. In the <bindings> node, you will find configuration elements similar to <binding protocol="http" bindingInformation="*:56422:localhost" />. Modify the port number 56422 to your desired value, for example: <binding protocol="http" bindingInformation="*:44444:localhost" />.

This approach offers the advantage of supporting more complex binding configurations, such as using custom domain names. For instance, configuring <binding protocol="http" bindingInformation="*:80:mysite.dev" /> and then mapping mysite.dev to 127.0.0.1 in the system's hosts file enables website access via http://mysite.dev.

Special Handling for Website Projects

For Web Site Projects, where Visual Studio interface doesn't support direct project URL modification, alternative approaches are necessary. Begin by removing the project from the solution, then modify the port configuration in ApplicationHost.config using the method described above.

After making changes, re-add the project to the solution using the "Add Existing Web Site" functionality. In the addition dialog, select the "Local IIS" tab and choose the corresponding website from the IIS Express sites list.

Configuration Differences in .NET Core Projects

In .NET Core projects, port configuration resides in the Properties\launchSettings.json file. Open this file and modify the port number in the applicationUrl property within the iisExpress section.

Configuration file example: { "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "http://localhost:53950/", "sslPort": 0 } }, "profiles": { "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } } } }

After modification, restarting Visual Studio may be necessary for changes to take effect. Configuration can also be performed through the graphical interface by double-clicking project properties.

Configuration Verification and Troubleshooting

Following port modification, comprehensive testing and verification are essential. Beyond basic page access testing, examine the following aspects: whether the port is occupied by other programs, firewall settings permitting port access, and correct virtual directory permissions.

If configurations don't take effect, try clearing browser cache, restarting IIS Express service, or checking ApplicationHost.config file syntax. In rare cases, running Visual Studio with administrator privileges may be required.

Through these methods, developers can flexibly configure IIS Express port settings to meet various development and testing requirements. Establishing unified port configuration standards in team development environments is recommended to avoid port conflicts and configuration inconsistencies.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.