ASP.NET Core - 提供静态文件服务

7

我正在遵循这份文档,但是遇到了一些困难:

https://learn.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>页面?
1个回答

12

你需要创建中间件或URL重写来完成工作。ASP.NET Core并不是最聪明的,也不会为你手动做这些事情。

在你的Program.cs文件中,你还应该执行WebHostBuillder.UseWebRoot(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "dist"))

此外,这看起来像是这个问题的副本


1
是的,他只需要将WebRoot从wwwroot更改为wwwoot/dist。不需要新的中间件。 - Juergen Gutsch

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接