.NET Core更改我的默认index.html文件所在的位置 [英] .NET Core changing the location where my default index.html file is
问题描述
我正在构建Angular 2应用程序,并使用.NET Core和Webpack将我的静态资源编译到dist文件夹中.我正在使用一个插件来构建我的index.html文件,并将其放在我的wwwroot/dist文件夹中,但是正在努力配置我的Startup.cs文件以在dist文件夹中查找默认文件.
I am building an Angular 2 app and using .NET Core and Webpack to compile my static resources into a dist folder. I am using a plugin that builds my index.html file and puts it in my wwwroot/dist folder but am struggling on how to configure my Startup.cs file to look for the default file in the dist folder.
目前我有...
app.UseDefaultFiles();
app.UseStaticFiles();
在我的startup.cs文件中,但不会使用在dist文件夹中生成的index.html.关于我需要更改的任何想法?我没有找到关于如何执行此操作的文档.
In my startup.cs file but it will not use the index.html that is generated in my dist folder. Any ideas on what I need to change? The docs do not give much reference from what I could find on how to do this.
谢谢.
推荐答案
您可以使用下面的代码,但是仅当在 wwwroot 文件夹的根目录中放置空的index.html时,它才有效:/p>
You can use code like below, but it only works when you put empty index.html in the root of wwwroot folder:
app.UseDefaultFiles();
// Serve wwwroot/dist as a root
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\dist"))
});
RequestPath默认情况下为空,因此根路径将显示wwwroot \ dist文件夹中的index.html或default.html.
RequestPath is empty by default so root path will show you index.html or default.html from wwwroot\dist folder.
更新:有一个简单美观的解决方案,可以使用Program.cs
中的 WebRoot 来解决此问题,如下所示:
UPDATE: There is easy and beautiful solution to handle this issue using WebRoot in Program.cs
like below:
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseWebRoot(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "dist"))
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.UseApplicationInsights()
.Build();
host.Run();
}
在Startup.cs
的Configure
方法中,您只需使用:
In Configure
method of Startup.cs
you just use:
app.UseDefaultFiles();
app.UseStaticFiles();
这篇关于.NET Core更改我的默认index.html文件所在的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!