Running a .NET Core 3.0 app using the default dotnet CLI Angular template behind a proxy may return unexpected results.
Steps to reproduce the behavior:
dotnet new angular -n HelloWorld)ERR_UNEXPECTED_PROXY_AUTH others will show the corporate proxy pageThe application should run without error.
NOTE: I was able to workaround this by adding localhost to my NO_PROXY environment variable.
You can argue that localhost should have been in my NO_PROXY list to begin with, but again it worked just fine in .NET 2.x.
@miguellira Thanks for contacting us.
I'm not really sure what changed here. This is likely a change in angular (we've upgraded several versions).
Does adding the following inside your profile in launchSettings.json fix the issue?
"environmentVariables": {
"NO_PROXY": "localhost",
}
See https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-3.0#development for a sample launchSettings.json profile (you should have one under /properties/ in your project root)
@javiercn Yes. Modifying the launchSettings.json file "fixes" this.
I don't believe it is an issue with Angular or the version referenced in the .NET Core 3.0 templates. The AngularCLIMiddleware works as expected. A random port is assigned and the ng serve command is executed. I can actually hit the Angular app directly from the browser. However, when a request to http://localhost:5001 is made it is suppose to get proxied to the running Angular app and it is at that point that the proxy error arises.
@miguellira Thanks trying it out.
@SteveSandersonMS I believe this might be caused by how the requests are being proxied from the middleware?
Could we configure the HttpClient instance I imagine the middleware is using to not use a proxy under any circumstances?
I imagine that should be safe, simple and transparent.
Alternatively we could add this to launchSettings.json or as a last resort we could simply choose to document it, as it鈥檚 not a very common case.
Thoughts?
Yes, that sounds believable. If we can make the middleware never use an external proxy (assuming it's only ever used to access a dev server running on localhost) that would be a clean fix.
We've moved this issue to the Backlog milestone. This means that it is not going to happen for the coming release. We will reassess the backlog following the current release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources.
The react template seems to have the same issue.
It seems like something has changed in the way the httpclient is working in .netcore 3.
see also my comment in:
I can confirm adding "NO_PROXY": "localhost" works :) thanks!
I am using Visual studio 2019, .net core 3.1, with Angular8 template, when using SPA modes:
spa.UseProxyToSpaDevelopmentServer
or
spa.UseAngularCliServer
I was getting a proxy message stating can't forward to localhost.
For some reason my proxy settings from "Internet Options" stopped working, I had HTTP_PROXY and HTTPS_PROXY set, but not NO_PROXY. My side by side install of Visual studio 2017 and .net core 2.1 worked fine.
Using our proxy pac file with localhost allowing direct connection didn't work. Setting "Internet Options" to bypass for local addresses or manual exceptions also didn't work.
Adding NO_PROXY environment variable with value localhost fixed my issue.
Same issue.
This problem doesn't occur on macOS but on Windows
Sorry. The cause was not the OS.
The problem was how to write the NO_PROXY(environment variable) .
I experienced this when migrating a project from .NET Core 2.2 to 3.1.
I actually was talking to the corporate help desk for a bit since I thought it was a networking issue. Whoops.
VS2019 16.5, Angular 8.
I use HTTP_PROXY and HTTPS_PROXY for Unity proxy support. It sounds like someone else in this thread uses them too so that might be exposing the problem?
Adding NO_PROXY worked for me too.
It should be noted the telltale sign of this problem is seeing the corporate proxy page for the Angular server url, not the url you entered -- ASP.NET Core is mirroring the page back to you thinking it is your SPA.
I just spent a whole day attempting to get an angular project running. There are many options I tried and with angualr timing out this was very hard to pin down. Almost resorted back to running ngserve and dontet API as separate projects. Thank you for the workaround, I was surprised to learn that a proxy would affect a development environment like this. Hope this is fixed quickly or documented better.
Most helpful comment
@miguellira Thanks for contacting us.
I'm not really sure what changed here. This is likely a change in angular (we've upgraded several versions).
Does adding the following inside your profile in launchSettings.json fix the issue?
See https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-3.0#development for a sample launchSettings.json profile (you should have one under /properties/ in your project root)