I am looking for a code based solution to only serving static files from a specified directory using ASP.NET routing rather than specify a HttpHandler
in the Web.config
.
For example:
I have the following partial directory layout
/
/public
/public/hello.txt
/public/css
/public/css/base.css
/readme.txt
If any files are requested from the /public
directory they should be served as-is. If any other static files are requested for example /readme.txt
it should be served as a 404
. The directory which allows static files to be served from should be easily specified as a string (var publicDir = "public";
).
I am looking to do this with little to no configuration required in the Web.config
file, and most of it configured in code.