我有一个.Net Core 2 WebAPI项目,该项目需要服务两个UI应用程序:
我在wwwroot
文件夹下有两个应用程序的构建文件。
此外,我还为.Net Core项目中的特定文件夹提供静态文件:
app.UseStaticFiles(new StaticFileOptions
{
ServeUnknownFileTypes = true,
RequestPath = $"/Catalog",
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "Catalog")),
OnPrepareResponse = ctx =>
{
ctx.Context.Response.Headers.Append("Cache-Control", "public,max-age=600");
},
});
为托管有角度的应用程序,我尝试了几种方法:
// this will serve wwwroot/app/index.html when path is '/app'
app.UseDefaultFiles("/app");
app.UseStaticFiles("/app");
app.UsePathBase("/app");
// this will serve wwwroot/admin/index.html when path is '/admin'
app.UseDefaultFiles("/admin");
app.UseStaticFiles("/admin");
app.UsePathBase("/admin");
app.UseDefaultFiles(new DefaultFilesOptions
{
RequestPath = $"/app",
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/app"))
});
app.UseStaticFiles(new StaticFileOptions
{
RequestPath = $"/app",
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/app"))
});
app.UseDefaultFiles(new DefaultFilesOptions
{
RequestPath = $"/admin",
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/admin"))
});
app.UseStaticFiles(new StaticFileOptions
{
RequestPath = $"/admin",
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/admin"))
});
但是当导航到http://192.168.12.126:44389/app/
或http://192.168.12.126:44389/admin/
时,我只会得到空白页。