My web application needs to let an admin user add and remove served folders from a .net core 2 app. I have found a way to provide a list of served folders, but I can't find a way to dynamically add or remove them once the app has been configured.
How do I re-run the configure function from within the application? Alternatively, how do I add or remove UseFileServer() configurations within an already-running service?
public class Startup
{
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseDeveloperExceptionPage();
app.UseMvc();
//get these dynamically from the database
var locations = new Dictionary<string, string>{
{@"C:\folder1", "/folder1"},
{@"D:\folder2", "/folder2"}
};
foreach (var kvp in locations)
{
app.UseFileServer(new FileServerOptions()
{
FileProvider = new PhysicalFileProvider(
kvp.Key
),
RequestPath = new PathString(kvp.Value),
EnableDirectoryBrowsing = true
});
}
}
}
I'm using .net core 2.0.0-preview2-final.