Closed drauch closed 6 years ago
It looks like the problem is with UseUrls() if the URL contains a base path. If we remove the base path it works. However, we want to apply such a base path FROM OUTSIDE - how to do so? (please don't tell me to call UseBasePath inside Startup.Configure, that's not from outside)
@JunTaoLuo is this the same issue as https://github.com/aspnet/Home/issues/3495?
Though this is the same error, I think the scenario is different.
@drauch what do you mean by "from outside"? Is the requirement here to set the base path based on an environment variable? If so, I think it would be easiest to set two separate environment variables, one for the url and one for the path base and call UseUrls and UseBasePath on the two environment variables. While we have an explicit configuration key for urls: https://github.com/aspnet/Hosting/blob/master/src/Microsoft.AspNetCore.Hosting.Abstractions/WebHostDefaults.cs#L17, we don't have one for base path: https://github.com/aspnet/Hosting/issues/1120. You'll need to set and read your own environment variable with a custom name.
@JunTaoLuo : "from outside" = "without touching the Startup class or its Configure method". It should be set from the WebHostBuilder.
Unfortunately we don't have a first class way of doing this on the WebHostBuilder. The issue I linked https://github.com/aspnet/Hosting/issues/1120 is the enhancement that would address this. Closing as dupe cc @Tratcher @davidfowl.
@drauch The closest thing I can think of to what you want to do is to create a StartupFilter that adds the call to UsePathBase:
public class PathBaseStartupFilter : IStartupFilter
{
public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
{
return builder =>
{
builder.UsePathBase(Environment.GetEnvironmentVariable("CUSTOM_PATH_BASE"));
next(builder);
};
}
}
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureServices(services =>
{
services.AddTransient<IStartupFilter, PathBaseStartupFilter>();
})
.UseStartup<Startup>();
}
@JunTaoLuo : Thank you for the workaround! Hope that https://github.com/aspnet/Hosting/issues/1120 will be implemented!
In our web tests we host a Kestrel server for our web assembly, in 1.x we did it in the following way:
Moving to 2.x we used the new program pattern instead:
However, now we run into the following problem:
What's the correct way to do this?