【问题标题】:ASP.NET Core - serving static files [duplicate]ASP.NET Core - 提供静态文件 [重复]
【发布时间】:2018-07-11 04:02:40
【问题描述】:

我正在关注此文档,但我遇到了困难: 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】:

    您将创建中间件或重写 URL 来为您完成工作。 ASP.NET Core 不是最聪明的,它不会手动为您做事。

    您还应该在您的Program.cs 文件中使用WebHostBuillder.UseWebRoot(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "dist"))

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

    【讨论】:

    • 是的,他只需要将 WebRoot 从 wwwroot 更改为 wwwoot/dist。真的不需要新的中间件