Preventing All File Downloads in Folder with Web.config File

Preventing All File Downloads in Folder with Web.config File

If you ever happen to need to prevent files from being downloaded from a particular folder, you can add this web.config to that folder:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="Disable File Downloads" path="*" verb="*" type="System.Web.HttpNotFoundHandler" />
    </handlers>
  </system.webServer>
</configuration>

I have tested this with IIS 10, though I believe it works with most modern versions of IIS (say, IIS 7 and greater).

Much of this was derived from this Stack Overflow post: https://stackoverflow.com/a/27947061/2052963