I have an ASP.NET Core 5 MVC application which serves multiple sites using the ASP.NET Core Web Optimizer; e.g.,
https://example.com
https://example.com/store1
https://example.com/store2
All sites have same wwwwroot
directory.
I tried code below to provide a single wwwwroot
in my startup.cs
and it worked. However, Guru wrote that every middleware should be called only once.
How do I serve multiple sites using the same wwwroot
directory?
In my startup.cs
:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseWebOptimizer();
app.UseWebOptimizer(env, new FileProviderOptions[] { new FileProviderOptions()
{
RequestPath = new PathString("/store1"),
FileProvider = env.WebRootFileProvider
}
});
app.UseWebOptimizer(env, new FileProviderOptions[] { new FileProviderOptions()
{
RequestPath = new PathString("/store2"),
FileProvider = env.WebRootFileProvider
}
});
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions
{
RequestPath = new PathString("/store1")
});
app.UseStaticFiles(new StaticFileOptions
{
RequestPath = new PathString("/store2")
});
}