asp.net – 默认情况下提供静态文件index.html

我有一个非常简单的角度应用程序项目,只需要提供来自wwwroot的静态文件.这是我的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?

解决方法

您想要服务器文件静态文件
public void Configure(IApplicationBuilder application)
{
    ...
    // Enable serving of static files from the wwwroot folder.
    application.UseStaticFiles();
    // Serve the default file,if present.
    application.UseDefaultFiles();
    ...
}

或者,您可以使用UseFileServer方法,该方法使用单行而不是两行来执行相同的操作.

public void Configure(IApplicationBuilder application)
{
    ...
    application.UseFileServer();
    ...
}

有关更多信息,请参见documentation.

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....