Abdul Rehman Sayed
Abdul Rehman Sayed

Reputation: 6672

What is the difference between app.usestaticfiles & app.usefileserver for OWIN

I want to know what is the difference between these two blocks of code for OWIN.

It seems to me that they are doing the same job.

1.

 string root = AppDomain.CurrentDomain.BaseDirectory;
            var physicalFileSystem = new PhysicalFileSystem(Path.Combine(root, "wwwroot"));
            var options = new FileServerOptions
            {
                RequestPath = PathString.Empty,
                EnableDefaultFiles = true,
                FileSystem = physicalFileSystem
            };
            options.StaticFileOptions.FileSystem = physicalFileSystem;
            options.StaticFileOptions.ServeUnknownFileTypes = false;

            app.UseFileServer(options);

2.

    app.UseStaticFiles("wwwroot");

Upvotes: 4

Views: 1736

Answers (1)

Marco
Marco

Reputation: 23935

IAppBuilder.UseFileserver combines UseStaticFiles UseDefaultFiles, but not UseDirectorybrowser by default.

That means:

app.UseFileServer(enableDirectoryBrowsing: true); 

enables all of the above, while

app.UseFileServer();

only enables static files and default files, but not directory browsing. In reverse that means, that IAppBuilder.UseStaticFiles only enables the webserver to serve static files, but does not make any assumptions about default documents or directory browsing.

Upvotes: 5

Related Questions