c# – ASP.NET核心 – 提供静态文件
作者:互联网
参见英文答案 > .NET Core changing the location where my default index.html file is 2个
我正在关注此文档,但我遇到了问题:
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/static-files
考虑我的目录结构:
wwwroot
dist
index.html
在我的启动课上,我有:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "dist"))
});
}
当我启动应用程序时,我没有看到我的index.html页面,但是如果我导航到< host> /dist/index.html
如何配置此项以便ASP.NET自动将我从< host>?带到该页面
解决方法:
您将创建中间件或URL重写来为您完成工作. ASP.NET Core并不是最聪明的,也不会为您手动执行操作.
您还应该在Program.cs文件中执行WebHostBuillder.UseWebRoot(Path.Combine(Directory.GetCurrentDirectory(),“wwwroot”,“dist”)).
此外,这看起来像this.的副本
标签:c,asp-net-core,static-files 来源: https://codeday.me/bug/20190607/1195265.html