c# - ASP.NET Core - 提供静态文件

标签 c# asp.net-core static-files

<分区>

我正在关注这个文档,但我被卡住了: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files

考虑我的目录结构:

wwwroot
    dist
        index.html

在我的创业课上,我有:

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,我会看到

我如何配置它以便 ASP.NET 自动将我从 <host> 转到该页面?

最佳答案

您需要创建中间件或重写 URL 来为您完成这项工作。 ASP.NET Core 不是最智能的,它不会手动为您做事。

您还应该在 Program.cs 中执行 WebHostBuillder.UseWebRoot(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "dist"))文件。

此外,这看起来像是 this. 的副本

关于c# - ASP.NET Core - 提供静态文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48552422/

相关文章:

c# - OAuth C# 服务器

c# - 使用naudio动态播放音频文件

asp.net-core - AspNet Core 脚手架应用程序中的登录和注册页面在哪里?

python - Flask 静态文件 Cache-Control

django - 静态文件不适用于 Django、Heroku 和 Django Sass 处理器

c# - 使用数据绑定(bind)的 C#/WPF 中具有确定/取消行为的对话框

c# - 如何解决 SqlException 在锁定时死锁 |通信缓冲资源

angular - 使用 asp .net core 3 API 登录 Angular SPA,无需重定向到 SPA 之外

c# - SelectList当bindproperty需要的值是asp.net和entity framework中的一个类

java - Spring启动: How to exclude static files from building . war文件?