Default static file use

public static class Sample03
{
    public static void Run()
    {
        var path = Path.Combine(Directory.GetCurrentDirectory(), "content");
        var fileProvider = new PhysicalFileProvider(path);

        var staticFileOptions = new StaticFileOptions
        {
            FileProvider = fileProvider,
            RequestPath = "/content"
        };

        // Directory browsing middleware configuration
        var directoryBrowserOptions = new DirectoryBrowserOptions
        {
            FileProvider = fileProvider,
            RequestPath = "/content"
        };

        Host.CreateDefaultBuilder()
            .ConfigureWebHostDefaults(builder => builder.Configure(
                app=>app
                    Directory browsing middleware.UseStaticFiles() .UseStaticFiles(staticFileOptions) .UseDirectoryBrowser() .UseDirectoryBrowser(directoryBrowserOptions))) .Build() .Run(); }}Copy the code
public static class Sample05
    {
        public static void Run()
        {
            var options = new StaticFileOptions
            {
                ServeUnknownFileTypes = true,
                DefaultContentType = "image/jpg"}; Host.CreateDefaultBuilder() .ConfigureWebHostDefaults(builder => builder.Configure( app=>app .UseStaticFiles(options) .UseDirectoryBrowser())) .Build() .Run(); }}Copy the code
public static class Sample06
    {
        public static void Run()
        {
            var contentTypeProvider = new FileExtensionContentTypeProvider();
            contentTypeProvider.Mappings.Add(".abc"."images/jpg");

            var options = newStaticFileOptions { ContentTypeProvider = contentTypeProvider }; Host.CreateDefaultBuilder() .ConfigureWebHostDefaults(builder => builder.Configure( app=>app .UseStaticFiles(options) .UseDirectoryBrowser())) .Build() .Run(); }}Copy the code

Setting the Default page

 public class Sample04
    {
        public static void Run()
        {
            var path = Path.Combine(Directory.GetCurrentDirectory(), "content");
            var fileProvider = new PhysicalFileProvider(path);

            var staticFileOptions = new StaticFileOptions
            {
                FileProvider = fileProvider,
                RequestPath = "/content"
            };

            var directoryBrowserOptions = new DirectoryBrowserOptions
            {
                FileProvider = fileProvider,
                RequestPath = "/content"
            };

            // Default page middleware configuration
            var defaultFilesOptions = new DefaultFilesOptions
            {
                FileProvider = fileProvider,
                RequestPath = "/content"
            };
            defaultFilesOptions.DefaultFileNames.Add("readme.html");

            Host.CreateDefaultBuilder()
                .ConfigureWebHostDefaults(builder => builder.Configure(
                    app=>app
                        // Default page middleware.UseDefaultFiles() .UseDefaultFiles(defaultFilesOptions) .UseStaticFiles() .UseStaticFiles(staticFileOptions) .UseDirectoryBrowser() .UseDirectoryBrowser(directoryBrowserOptions))) .Build() .Run(); }}Copy the code