【发布时间】:2019-05-18 22:14:05
【问题描述】:
我正在尝试使用Kestrel 使用FileProvider 扩展部署Angular 7 应用程序和.NET Core。
我已经创建了 Angular 应用程序,我有 ng build 它,我复制了 dist .NET Porject 中的文件。
启动
public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
string jsFolderName = "myroot";
string prodRoot =Path.Combine(AppDomain.CurrentDomain.BaseDirectory,jsFolderName);
string debugRoot =Path.Combine(Directory.GetCurrentDirectory(),jsFolderName);
var isDev=env.IsDevelopment();
DefaultFilesOptions options = new DefaultFilesOptions();
options.DefaultFileNames.Clear();
options.DefaultFileNames.Add("/myroot/index.html");
app.UseDefaultFiles(options);
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions() {
FileProvider = new PhysicalFileProvider(isDev?debugRoot:prodRoot),
RequestPath = "/app"
});
if (env.IsDevelopment()) {
app.UseDeveloperExceptionPage();
} else {
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseMvc();
}
P.S 我的myroot 文件夹就在项目的根目录中。
我不知道如何提供angular 应用程序的第一页(入口点),即index.html。
【问题讨论】:
-
为什么不使用现成的模板?我建议你看看Mark Pieszak's AspNetCore Angular Universal Template 或者你可以使用微软的 Angular 模板,它已经在 VS2017 中可用
标签: asp.net-core ng-build fileprovider-extension