I have a visual studio solution for an ASP.NET Core application. This ASP.NET Core application also uses Microsoft.AspNetCore.SpaServices to render a React SPA. On some PCs, it runs as expected: when launching it in debug mode through visual studio, it loads up on the configured address and port (localhost:3000).
I recently upgraded to Windows 11. Ever since after that, when I try to run the project, visual studio will fire up a web browser, load the app on the configured port (localhost:3000), then switch to a random port! (in the 50000 range). Note that the same project, on the same version in git, launches as expected (loads and stays on localhost:3000) on other PCs running Windows 10.
Additionally, I can run other applications, like a react frontend on port 3000 at a separate time with no incident.
launchsettings.json looks like this:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:3000",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
}
}
}
When I turn on tracing, I can see that Microsoft.AspNetCore.SpaServices
reports a new, random port number as the port to serve the application from:
2022-12-23 10:19:32.1515|INFO|Microsoft.AspNetCore.SpaServices|You can now view myapp.name in the browser.
2022-12-23 10:19:32.1515|INFO|Microsoft.AspNetCore.SpaServices| Local: http://localhost:52371
2022-12-23 10:19:32.1515|INFO|Microsoft.AspNetCore.SpaServices| On Your Network: http://10.11.12.13:52371
(names and IP addresses anonymized.)
Why visual studio / IIS express changing this port number on load, and how can I make it stop?
CodePudding user response:
The solution for me ended up being related to zscalar's proxy behind the corporate firewall. I needed to ensure that localhost and 127.0.0.1 were added to the NO_PROXY
environment variable.
The string "_sm_au_"
being appended to the URL (like localhost:56912/?_sm_au_=123vAB12AB842t12
" ) was a sign that zscalar was involved, as I found originally here: https://stackoverflow.com/a/72735926/18097