【发布时间】:2019-07-29 15:46:16
【问题描述】:
我在一个 asp.net 核心应用程序中有多个 Angular 应用程序。 现在我想将其中一个设置为默认值。假设当我运行该应用程序时,它会自动转到 Angular Home 应用程序。 方案结构:SQL->EntityFrameworkCore->.NET Core->Angular application(HomeApp, App1, App2....)
现在,在我运行应用程序后,我必须转到 URL 并输入:localhost:5000/home Togo 到 Angular Home 应用程序。否则,它不会显示任何内容。
我尝试使用 asp.net core Map 和 UserSpaStaticFiels。
在我设置的每个角度 app1、app2 index.html 文件中
<base href="/home/">
在 startup.cs 中我设置的代码是这样的:
<i>
// For each angular application we want to host:
app.Map(new PathString("/home"), home =>
{
if (env.IsDevelopment())
{
StaticFileOptions clienthome = new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), @"home"))
};
home.UseSpaStaticFiles(clienthome);
home.UseSpa(spa =>
{
spa.Options.SourcePath = "home"; // spa.Options.StartupTimeout = new TimeSpan(0, 5, 0);
spa.UseAngularCliServer(npmScript: "start"); // it will use package.json & will search for start command to run
});
}
else
{
// Each map gets its own physical path for it to map the static files to.
StaticFileOptions clienthome = new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), @"home/dist"))
};
// Each map its own static files otherwise it will only ever serve index.html no matter the filename
home.UseSpaStaticFiles(clienthome);
// Each map will call its own UseSpa where we give its own sourcepath
home.UseSpa(spa =>
{
spa.Options.StartupTimeout = new TimeSpan(0, 1, 30);
spa.Options.SourcePath = "home";
spa.Options.DefaultPageStaticFileOptions = clienthome;
});
}
});
</i>
我的期望是:当我启动 Visual Studio 时,asp.net 核心应该只运行家庭应用程序,而不需要转到 url 和类型 localhost:5000/Home。
【问题讨论】:
标签: angular asp.net-core