Based on this SO answer: https://stackoverflow.com/a/2066040/458354 I have a web.config that defines a custom HttpHandler for all files in a subdirectory, placed in my static file subdirectory. This works perfectly if the directory, even when configured as virtual, is on the same server as IIS. However, if the virtual directory points to a shared folder on another server, I receive this error when accessing a static resource: “An error occurred loading a configuration file: Invalid file name for file monitoring: ‘\\remoteserver\remotedir\web.config’.”
I’ve even granted permissions on the remote directory to the IIS_IUSR from the webserver. I suspect the problem is the config path being a share. Any thoughts on an way to allow the virtual dir web.config to be read by IIS?
Alternatively, is there a way to configure the handler path in the site’s normal web.config to cover an entire subdirectory?
Config line in question:
<add name="MyRequestHandler" type="MyApp.StaticFileRequestHandler,
MyApp" path="*" resourceType="Either" verb="GET,HEAD"
requireAccess="Read"/>
See 401 Unauthorized when custom IHttpHandler tries to read from virtual directory . Set the ApplicationPool identity to the same identity that will be used to connect to the remote virtual directory (could be a service account, for example).
Also, with regard to alternate ways to assign a Handler to a subdirectory, I ended up changing the application design to use asp.net routing (not MVC) and having the url request specify the desired static file by an identifier (which may not always be desirable, but was already an existing practice elsewhere in our application landscape). This eliminates the need for a child web.config in the virtual directory, as the Handler can then be assigned programatically:
The identifier is no longer a wildcard, but a
RouteDataparameter. (Not sure if this would work if the identifier were a filename with a ‘dot’ and extension…).