ASP.NET核心 - 提供静态文件[复制]

问题描述 投票:4回答:1

这个问题已经在这里有一个答案:

我下面这个文档,但我卡住: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>

c# asp.net-core static-files
1个回答
5
投票

你必须创建中间件或URL重写做的工作适合你。 ASP.NET的核心是不是最聪明的,它是不会为你做手工的东西。

你也应该在你的WebHostBuillder.UseWebRoot(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "dist"))文件做Program.cs

此外,这看起来像this.的副本

© www.soinside.com 2019 - 2024. All rights reserved.