0

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"/>
Community
  • 1
  • 1
mdisibio
  • 3,148
  • 31
  • 47
  • Actually, the config file in the remote share is accessed just fine. I have narrowed the problem down to the "path" value. If it is the wildcard only, or an extension that is requested, the error is raised, but not if the the path is an specific extension not being requested... – mdisibio Jan 08 '13 at 21:25
  • The setup was fine. Seems to be a permissions problem of the AppPool identity, as in [http://stackoverflow.com/q/10354748/458354](http://stackoverflow.com/q/10354748/458354). Setting the ApplicationPool identity to the same identity used to connect to the remote virtual directory allows the handler to run for the subdirectory as expected. Giving the connection user permissions to the directory is not enough for the handler. – mdisibio Jan 08 '13 at 23:03

1 Answers1

0

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:

public static void RegisterRoutes(RouteCollection routes)
{
    // fileId must be all digits, with at least one digit
    var routeConstraints = new RouteValueDictionary { { "fileId", @"\d{1,}" } };
    var getProtectedFileRoute = new Route("resources/files/{fileId}", new MyFileRequestRouteHandler())
    {
        Constraints = routeConstraints
    };
    routes.Add(getProtectedFileRoute);
}

The identifier is no longer a wildcard, but a RouteData parameter. (Not sure if this would work if the identifier were a filename with a 'dot' and extension...).

Community
  • 1
  • 1
mdisibio
  • 3,148
  • 31
  • 47