【发布时间】: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