如何在1 .Net Core 2服务中托管2个角度应用程序?

时间:2018-07-25 12:00:50

标签: asp.net-core-2.0

我有一个.Net Core 2 WebAPI项目,该项目需要服务两个UI应用程序:

  1. 应用
  2. 管理员

我在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");
    },
});

为托管有角度的应用程序,我尝试了几种方法:

1

// 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");

2

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/时,我只会得到空白页。

0 个答案:

没有答案