我正在尝试在 Asp.Net Core 中使用 UseFileServer 但它不起作用

I am trying to use UseFileServer in Asp.Net Core and it's not working

我已经安装了 Microsoft.AspNetCore.StaticFiles(NuGet 包),下面是相关的启动代码。我在根目录和名为 static.

的文件夹中都有一个 index.html 文件

总而言之,这看起来很简单...不知道为什么我遇到了麻烦。

在我的本地主机上处于调试模式...我得到:

https://localhost:44331 (404)

https://localhost:44331/index.html (404)

https://localhost:44331/static (404)

https://localhost:44331/static/index.html (200)

https://localhost:44331/api/values (200)

当我发布到 azure web 应用程序服务器时,上述 url 的 none 有效,除了:

https://myserver.com/api/values (200)

    public class Program
    {
        public static void Main(string[] args)
        {
            CreateWebHostBuilder(args).Build().Run();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>();
    }



    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
            app.UseHsts();
        }

        app.UseHttpsRedirection();
        app.UseMvc();

        app.UseFileServer();
    }

根据答案更新(有效)

为了正确提供,您的文件应位于 wwwroot 文件夹中。

如果在 wwwroot 中你会把你的 index.html,那么你可以通过 htts://localhost:44331/index.html 访问它。