The static files like HTML, JavaScript, CSS, and images are served by the Web Server.
If we create an ASP.Net Core Web application using MVC or Angular or React templates, by default the application will be configured to serve static files.
But in case the application is built using the ASP.Net Core Web API template, the static files serving capacity is not configures by default. And we will have to do it using the Middleware provided.
In most cases, we will not need that. But there are some situations where we might want to expose an HTML file as a part of the ASP.Net Core Web API application. For showing some information like the configuration or some basic instructions about the application.
I personally have come across a situation, where I needed to expose a Web user interface to show the configuration used by the Web API. In those cases creating a web application using MVC or Angular is an overkill. Also, there is a lot of extra work in terms of maintaining it. In those cases, creating a simple HTML file with some AJAX calls are perfect.
I will not recommend this solution for any professional Web Application with complex user flow. In that case, we should be using a SPA framework like Angular or React.
This solution is useful for creating a simple page for support and/or the administrative purpose for a Web API (only services based application).
The complete source code for this video is available in GitHub here: https://github.com/choudhurynirjhar/static-files-demo
#aspdotnet #web-development