【问题标题】:I am trying to use UseFileServer in Asp.Net Core and it's not working我正在尝试在 Asp.Net Core 中使用 UseFileServer 但它不起作用
【发布时间】:2019-06-16 14:41:54
【问题描述】:

我已经安装了 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 应用服务器时,上述网址均无效,除了:

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();
    }

根据答案更新(有效)

【问题讨论】:

    标签: asp.net asp.net-core static-files


    【解决方案1】:

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

    如果您将index.html 放入wwwroot,那么您可以通过htts://localhost:44331/index.html 访问它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-30
      • 1970-01-01
      • 2019-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-28
      相关资源
      最近更新 更多