Dev server cannot reach the ASP.NET Core API in a Visual Studio SPA project
http proxy error at /weatherforecastShort answer
The dev server forwards /weatherforecast to the ASP.NET Core backend. The error means nothing answered at the target address. Check three things: the backend started first, the port in the proxy target matches applicationUrl in launchSettings.json, and with Docker the target uses the container's HTTPS port.
Fix it fast
1Find out which cause you have
Find the backend address and see whether anything listens there. Take the https applicationUrl from launchSettings.json.
grep -n "applicationUrl" Properties/launchSettings.json curl -k -I https://localhost:7049/weatherforecast2Match what you see, then jump to its fix
- 1
ECONNREFUSED on the first request only; refreshing the browser later worksThe front end started before the backendFix - 2
ECONNREFUSED to a port the backend never uses, for example 5001 while launchSettings.json says 7049The proxy target port does not match the backend portFix - 3
The API works inside Visual Studio's Containers window, but the proxy target is still the old localhost portThe backend runs in Docker on a different HTTPS portFix
- 1
What does the error look like?
http proxy error at /weatherforecast[HPM] Error occurred while trying to proxy request /weatherforecast from localhost:4200 to https://localhost:5001 (ECONNREFUSED)Weather forecast data never loads in the browser
Cause 1 of 3
The front end started before the backend
1Check
Watch the two console windows Visual Studio opens. If the Angular or Vite window shows the proxy error before the API window says it is listening, the order is wrong.
dotnet run --project AngularWithASP.Server2Fix
Wait until the backend window is running, then refresh the browser. Make the ASP.NET Core project first in the startup list (Solution Properties, Configure Startup Projects).
# Visual Studio: Solution Properties > Startup Project > Multiple projects > Action: Start, backend first3Verify
Start with F5 again; the weather data should load without a manual refresh.
curl -k https://localhost:7049/weatherforecastConfirmed by learn.microsoft.com
Cause 2 of 3
The proxy target port does not match the backend port
1Check
Compare the port in the proxy file (proxy.conf.js, or the server.proxy section of vite.config) with the https applicationUrl in the backend's launchSettings.json.
grep -n "applicationUrl" Properties/launchSettings.json
grep -n -E "target|proxy" vite.config.* proxy.conf.js 2>/dev/null2Fix
Set the proxy target to the https applicationUrl from launchSettings.json.
// proxy.conf.js (Angular template)
target: 'https://localhost:7049',
// vite.config.js (Vite based template)
server: {
proxy: {
'/weatherforecast': {
target: 'https://localhost:7049',
changeOrigin: true,
},
},
},3Verify
Restart the dev server, because proxy settings are read at start-up.
curl -I http://localhost:4200/weatherforecastConfirmed by learn.microsoft.com
Cause 3 of 3
The backend runs in Docker on a different HTTPS port
1Check
Open the Containers window in Visual Studio and read the HTTPS port on the Environment or Ports tab.
docker ps --format "table {{.Names}}\t{{.Ports}}"2Fix
Update the target to that HTTPS port. If the port is not shown, add sslPort to the Container (Dockerfile) profile in launchSettings.json, then restart.
const target = env.ASPNETCORE_HTTPS_PORT
? `https://localhost:${env.ASPNETCORE_HTTPS_PORT}`
: 'https://localhost:62958';3Verify
Restart the app and reload the page.
curl -k -I https://localhost:62958/weatherforecastConfirmed by learn.microsoft.com
How do I stop it coming back?
- Keep the backend first in the multiple-startup-projects list.
- After changing launchSettings.json, update the proxy target in the same commit.
- Read the proxy target from an environment variable instead of a hard-coded port.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Related fixes
Web apps
The Vite dev proxy does not forward my /api requests
The browser calls the backend directly instead of going through the Vite dev server
Vite proxies only requests whose path starts with a key in server.proxy, and it forwards the full path unless you rewrite it.
5 causes, each with a fixWeb apps
tsconfig rejects allowImportingTsExtensions
An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly
allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.
2 causes, each with a fixWeb apps
AuthUserPoolException: Auth UserPool not configured in a Next.js app
Auth UserPool not configured
The error means an Amplify Auth call ran before Amplify.configure did.
3 causes, each with a fixWeb apps
Module not found for antd/dist/antd.less after upgrading to Ant Design 5
Module not found: Error: Can't resolve 'antd/dist/antd.less'
Ant Design 5 dropped Less and the bundled CSS file for CSS-in-JS, so antd/dist/antd.less no longer exists.
3 causes, each with a fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
Apollo Client is blocked by CORS when the GraphQL server runs on AWS Lambda
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Apollo Server does not set CORS for you when it runs behind a framework or integration, and on Lambda that layer is API Gateway.
5 causes, each with a fix