diff --git a/src/Components/WebAssembly/Server/src/DebugProxyLauncher.cs b/src/Components/WebAssembly/Server/src/DebugProxyLauncher.cs index bdbd662b1237..1a1ba6b85e1e 100644 --- a/src/Components/WebAssembly/Server/src/DebugProxyLauncher.cs +++ b/src/Components/WebAssembly/Server/src/DebugProxyLauncher.cs @@ -52,6 +52,7 @@ private static async Task LaunchAndGetUrl(IServiceProvider serviceProvid UseShellExecute = false, RedirectStandardOutput = true, }; + RemoveUnwantedEnvironmentVariables(processStartInfo.Environment); var debugProxyProcess = Process.Start(processStartInfo); CompleteTaskWhenServerIsReady(debugProxyProcess, tcs); @@ -64,6 +65,21 @@ private static async Task LaunchAndGetUrl(IServiceProvider serviceProvid return await tcs.Task; } + private static void RemoveUnwantedEnvironmentVariables(IDictionary environment) + { + // Generally we expect to pass through most environment variables, since dotnet might + // need them for arbitrary reasons to function correctly. However, we specifically don't + // want to pass through any ASP.NET Core hosting related ones, since the child process + // shouldn't be trying to use the same port numbers, etc. In particular we need to break + // the association with IISExpress and the MS-ASPNETCORE-TOKEN check. + // For more context on this, see https://github.com/dotnet/aspnetcore/issues/20308. + var keysToRemove = environment.Keys.Where(key => key.StartsWith("ASPNETCORE_")).ToList(); + foreach (var key in keysToRemove) + { + environment.Remove(key); + } + } + private static string LocateDebugProxyExecutable(IWebHostEnvironment environment) { var assembly = Assembly.Load(environment.ApplicationName);