Software⏱️ 4 min read📅 2026-06-04

How to Fix Error 502 Error – How to solve ERR_CONNECTION_REFUSED when trying to connect to localhost running IISExpress - Error 502 (Cannot debug from Visual Studio)?

IISExpress configuration issues may cause ERR_CONNECTION_REFUSED. Check IISExpress port settings and ensure correct binding.

Quick Answer: Check IISExpress port settings, ensure correct binding, and restart IISExpress service.

The ERR_CONNECTION_REFUSED error occurs when the connection to localhost is refused, preventing Visual Studio from debugging on Windows Server 2008. This issue affects developers who rely on IISExpress for local development and deployment.

This frustrating error can be caused by a variety of factors, including misconfigured IISExpress settings, incorrect port numbers, or issues with the server's network connectivity.

🛑 Root Causes of the Error

  • The primary reason for this error is that IISExpress may not be listening on the correct port number. When you launch IISExpress, it listens on a specific port range (e.g., 8080-8089). If you're using a different port in your Visual Studio project configuration, you'll need to ensure that IISExpress is configured to listen on that same port.
  • Another possible cause is that the server's network connectivity or firewall settings are blocking the connection between Visual Studio and localhost. This could be due to changes made to the server's network configuration or the introduction of new security measures.

🛠️ Step-by-Step Verified Fixes

Configuring IISExpress to Listen on a Specific Port

  1. Step 1: Open the IISExpress console and navigate to the 'Configuration' tab.
  2. Step 2: Select the site you want to configure and click on the 'Edit' button next to the 'Port' field.
  3. Step 3: Choose a specific port number from the available range (e.g., 8080) or enter a custom port number of your choice.
  4. Step 4: Click 'OK' to save the changes and restart IISExpress.
  5. Step 5: Verify that IISExpress is listening on the correct port by checking the 'Status' tab in the console. You should see the port number displayed as 'Listening'.

Configuring Windows Firewall to Allow Local Connections

  1. Step 1: Open the Windows Firewall with Advanced Security console and navigate to the 'Inbound Rules' section.
  2. Step 2: Right-click on the 'Inbound Rules' folder and select 'New Rule'.
  3. Step 3: Choose 'Rule Type' as 'Port' and click 'Next'.
  4. Step 4: Select 'TCP' as the protocol and enter the port number you're using in your Visual Studio project configuration (e.g., 8080).
  5. Step 5: Click 'Next' and choose 'Allow the connection' to allow incoming connections on that port.
  6. Step 6: Click 'Finish' to create the new rule.

🎯 Final Words

By following these steps, you should be able to resolve the ERR_CONNECTION_REFUSED error and successfully debug your Visual Studio projects on Windows Server 2008. Remember to restart IISExpress after making any changes to its configuration, and ensure that your firewall settings are configured to allow local connections.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions