📜  在启动时设置自定义默认文件 - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:03.395000             🧑  作者: Mango

代码示例1
public class Startup
{
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        //Specify the MyCustomPage1.html as the default page
        DefaultFilesOptions defaultFilesOptions = new DefaultFilesOptions();
        defaultFilesOptions.DefaultFileNames.Clear();
        defaultFilesOptions.DefaultFileNames.Add("MyCustomPage1.html");

        //Setting the Default Files
        app.UseDefaultFiles(defaultFilesOptions);

        //Adding Static Files Middleware to serve the static files
        app.UseStaticFiles();

        app.Run(async (context) =>
        {
            await context.Response.WriteAsync("Request handled by the terminating middleware");
        });

    }
}