默认情况下提供静态文件index.html [英] Serve static file index.html by default

查看:74
本文介绍了默认情况下提供静态文件index.html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的角度应用程序项目,除了提供 wwwroot 中的静态文件外,无需执行其他任何操作.这是我的 Startup.cs :

I've got a very simple angular app project that needs to do nothing more than serve static files from wwwroot. Here is my Startup.cs:

public class Startup
{
    public void ConfigureServices(IServiceCollection services) { }

    public void Configure(IApplicationBuilder app)
    {
        app.UseIISPlatformHandler();
        app.UseStaticFiles();
    }

    // Entry point for the application.
    public static void Main(string[] args) => WebApplication.Run<Startup>(args);
}

每当我使用IIS Express或Web启动项目时,我总是必须导航到/index.html .我该如何做才能访问根目录(/)并仍然获得 index.html ?

Whenever I launch the project with IIS Express or web I always have to navigate to /index.html. How do I make it so that I can just visit the root (/) and still get index.html?

推荐答案

只需将 app.UseStaticFiles(); 更改为 app.UseFileServer();

public class Startup
{
    public void ConfigureServices(IServiceCollection services) { }

    public void Configure(IApplicationBuilder app)
    {
        app.UseIISPlatformHandler();
        app.UseFileServer();
    }

    // Entry point for the application.
    public static void Main(string[] args) => WebApplication.Run<Startup>(args);
}

这篇关于默认情况下提供静态文件index.html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆