Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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");
like image 475
Abdul Rehman Sayed Avatar asked Oct 21 '25 05:10

Abdul Rehman Sayed


1 Answers

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.

like image 95
Marco Avatar answered Oct 26 '25 19:10

Marco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!