问题描述
我正在关注此文档,但我被卡住了: https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/static-files
I'm following this documentation but I'm getting stuck:https://docs.microsoft.com/en-us/aspnet/core/fundamentals/static-files
考虑我的目录结构:
wwwroot
dist
index.html
在我的启动课程中,我有:
In my startup class, I have:
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
When I start the application I don't see my index.html page, but I do if I navigate to <host>/dist/index.html
如何配置它,以便ASP.NET自动将我从<host>
带到该页面?
How can I configure this so that ASP.NET automatically takes me to that page from <host>
?
推荐答案
您将创建中间件或URL重写为您完成工作. ASP.NET Core不是最聪明的,它也不会手动为您做事.
You'll have create middleware or a URL rewrite to do the work for you. ASP.NET Core isn't the smartest and it isn't going to manually do stuff for you.
您还应该在Program.cs
文件中执行WebHostBuillder.UseWebRoot(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "dist"))
.
You should also be doing WebHostBuillder.UseWebRoot(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "dist"))
in your Program.cs
file.
Also, this looks like a duplicate of this.
这篇关于ASP.NET Core-提供静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!