我已经安装了Microsoft.AspNetCore.StaticFiles(NuGet程序包),下面是相关的启动代码。我在根目录和名为static的文件夹中都有一个index.html文件。
总而言之,这似乎很简单……不确定我为什么遇到麻烦。
在本地主机上的调试模式下...我得到:
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均无效,除了:
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();
}
根据答案进行更新(有效)
答案 0 :(得分:0)
为了正确提供服务,您的文件应位于wwwroot
文件夹中。
如果您将wwwroot
放在index.html
中,则可以通过htts://localhost:44331/index.html
访问它。