ASP.NET Core 2.0 Static Files


How to serve static content (HTML, CSS, JavaScript, Images) from ASP.NET Core application.


Modify the Configure() method in Startup class to use middleware for static files:

Add static content to wwwroot and a custom content folder:

Static Files - Explorer

Access the files using site address:

  • http://[site-address]/hello.html
  • http://[site-address]/outside-content/info.html


Static files are served, by default, from wwwroot folder and can be accessed as if the content exist in your root folder. The default folder can be changed via WebHostBuilder in Program.cs using:

Static files can also be served from folders outside wwwroot by passing in StaticFileOptions to middleware and setting a FileProvider and RequestPath. This is useful when you want authorised access to files e.g. by returning FileResult action result from a secure controller.

Source Code


Leave a Reply