Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between UseStaticFiles() and UseFileServer() in ASP.NET Core?

Tags:

asp.net-core

I am confused between these two. What and when should be used in an ASP.NET web application?

like image 602
Nitin Rastogi Avatar asked May 16 '18 23:05

Nitin Rastogi


People also ask

What is UseStaticFiles?

The UseStaticFiles is an extension method included in the StaticFiles middleware so that we can easily configure it. Now, open the browser and send http request http://localhost:<port>/default.html which will display default. html as a response as shown below. Serving HTML File.

What is static files in ASP.NET Core?

Static files like JavaScript files, images, CSS files that we have on the file system are the assets that ASP.NET Core application can serve directly to clients. Static files are typically located in the web root (wwwroot) folder.

What is the default directory for static files in ASP.NET Core?

Static files are stored within the project's web root directory. The default directory is {content root}/wwwroot , but it can be changed with the UseWebRoot method.

Which of the following middleware must be installed to server static files in ASP.NET Core application?

To serve static files from an ASP.NET Core app, you must configure static files middleware. With static files middleware configured, an ASP.NET Core app will serve all files located in a certain folder (typically /wwwroot).


1 Answers

UseFileServer includes UseStaticFiles, UseDefaultFiles, and optionally UseDirectoryBrowsing. The average site only needs UseStaticFiles.

like image 161
Tratcher Avatar answered Sep 29 '22 08:09

Tratcher