IIS Express is running, but I get "Connection Refused" Error

Georg Aubele Lehmbau 0 Reputation points
2024-11-07T10:54:24.0666667+00:00

I'm developing an ASP.Net Web Form application and an ASP.Net Api.

/Edit: They are two different projects, have nothing to do with each other, but both have problems with IIS Express. /Edit

VS Studio 2022 is updated, no firewall or virus scanner is interfering

With both projects I have the problem, that the IIS Express does not deliver anything.
I even uninstalled and reinstalled Visual Studio 2022 and started a whole new project - which gave me the same result:
When I start debugging,

  • the memory usage of the app (shown in VS, process memory) is only about 18 MB - I know it should be at least around 200 MB or above!
  • The Browser starts (trying to show swagger in case of API or the web page in case of the Web Form App) and shortly after that shows, that localhost has refused the connection.
  • In the status bar the IIS Express icon is there, the web application is running and it shows me a http and a https connection for it with according ports.

But I can't access the information from the API or the web pages.

In Case of the API: When I change to http or https instead of IIS Express, the API works and I get a swagger browser window.

With the web form app I don't have such a possibility.

I tried several things:

  • ran VS 2022 as Admin
  • deleted the .vs folder in all three projects
  • deleted the IIS Express sub folder in the documents folder
  • changed the ports numbers in the applicationhost.config in the .vs/... sub folder
  • restarted my PC several times

Additional information:
A few days ago I deleted the SSL certificate for localhost and build a new one in the Nuget Package Manager Console with

dotnet dev-certs https --clean

dotnet dev-certs https --trust

dotnet dev-certs https --check

I did it. because in the API Project I could not access the https address (outside of the IIS Express, which was not working). This is possible now.

As mentioned above I get now that very low process memory usage.
Before the new SSL certificate, when tried to debug the web form app on IIS express, the memory usage was higher and I got an error message popping up that said that IIS could not be reached, but in the same message only one line below it stated that IIS Express started properly and managed to "connect" (could be wrong here, I don't remember the exact phrase) to the ports on local host.

Additional Information 2:

Trying to debug the API on IIS Express gives still the error message:
In the notificatoin bar on the bottom of VS 2022 it says:
"Web server failed to listen on Port 44301" (this is the SSL Port of IIS Express)
And the window pops up with

Unable to connect to web server 'IIS Express' Output from IIS Express: Starting IIS Express ... Succesfully registered URL 'http://localhost:20042/ for site 'MyAPI' application '/' Succesfully registered URL 'https://localhost:4403/ for site 'MyAPI' application '/' Registration completed for site 'MyAPI' IIS Express is running

Internet Information Services
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,550 questions
ASP.NET API
ASP.NET API
ASP.NET: A set of technologies in the .NET Framework for building web applications and XML web services.API: A software intermediary that allows two applications to interact with each other.
355 questions
{count} votes

1 answer

Sort by: Most helpful
  1. AgaveJoe 28,961 Reputation points
    2024-11-07T11:36:22.5266667+00:00

    A refused connection usually means a service is not running. If I understand your post, Swagger is able to interact with Web API. Therefore the Web API was running. I assume what's happening is you start the web application but not the Web API application or you start the Web API application but not the Web app.

    It's not clear how your solution is configured. If you have both application in one solution then right click the solution file in solution explorer and select properties. From here you can configure what applications start and if they start in debug mode or not.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.