set custom default file in startup

54

set custom default file in startup -

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");
        });

    }
}

Comments

Submit
0 Comments