0

My ASP.NET MVC project's root directory contains some typical static files, like robots.txt, manifest.json, browserconfig.xml, etc. If I'm not mistaken, each of these examples I listed should be able to be served with no involvement from MVC via GET requests to the root directory (i.e. mysite.com/manifest.json — if that's not true, please let me know).

I know from this answer that I can configure this behavior per file type in the Web.config. My question is, what if there are other .json files in my root directory that I don't want to serve, like compilerconfig.json or bundleconfig.json (both files generated by IDE tools)? What's the best way for the application to be able to serve some files of type X, but not others?

Jacob Stamm
  • 1,660
  • 1
  • 29
  • 53

1 Answers1

1

You can always ignore them via routes:

routes.IgnoreRoute("{somefilename}.json");

Another alternative would be to move the files you don't want to be served to another folder and add a web.config file to it to manage what gets served (or doesn't).

I am sure there are other ways. Modules come to mind...

JuanR
  • 7,405
  • 1
  • 19
  • 30
  • What do you mean by modules? – Jacob Stamm Oct 05 '17 at 18:29
  • You could create a module to inspect requests and handle accordingly. Check this out: https://www.codeproject.com/Articles/335968/Implementing-HTTPHandler-and-HTTPModule-in-ASP-NET – JuanR Oct 05 '17 at 18:32