Search code examples
httpwindows-7iis-7.5webdavhttpmodule

Load dynamic content based on user's credentials?


Is it possible, using WebDAV, to load dynamic content for each user (for example, maybe their files from our database) who maps their drive to our WebDAV share?

Every WebDAV implementation I've seen uses a Virtual Directory in IIS, and lets users map a network drive to that directory, ultimately syncing files/folders between the two.

What I'd like to do, if possible, is use WebDAV to let a user map their drive to a Virtual Directory, but only use the Virtual Directory for the sake of mapping their drive. I've got an HttpModule set up that will execute on WebDAV requests, so my idea was to let the HttpModule decide, based on the user, what files need to be loaded and create the virtual folder structure in their mapped drive from there.

Since multiple users will be accessing this drive, I don't actually want WebDAV to sync files back and forth between the Virtual Directory and the user's mapped drive. The idea is that we'll let the HttpModule detect what folder the user is in (from the request) and then load the files in from our database accordingly.

Is this possible? Or is there an alternative way to accomplish this? I realize that this may be using WebDAV for something other than it was intended for, but I wasn't sure if there were any other ways to let a user map a drive like this and detect requests coming from Windows Explorer. I'm using IIS 7.5 with VB.NET on Windows 7 currently for testing. I'll also need to implement security/authentication eventually, I was just hoping to get it working on a basic level first, so that's one thing to keep in mind.

UPDATE:

I've added RequestFiltering to my Web.config to not allow files with the extension ".txt" in hopes that they wouldn't get copied down to my local mapped drive (I copied a few text files into my Virtual Directory in IIS), but that wasn't the case - they always show up in the mapped drive. It appears that the RequestFiltering doesn't actually affect files showing up in my mapped drive, but instead just doesn't allow me to open them.

Is there a way to have WebDAV enabled for the sake of having a mapped drive to the share, but not allowing WebDAV to show/copy the files in the mapped drive? I'd like for it to work the same both ways, i.e. when copying files into the mapped drive, they shouldn't be copied into the Virtual Directory in IIS. I'd like to intercept those requests and handle copying the files to a different location (or into a database).


Solution

  • The solution I went with was to download the project from the link provided above by @User629926 and follow the logic of that project. The project clearly demonstrates how to use HttpModules & HttpHandlers to intercept WebDAV requests, and then dynamically build the response which allows me to display the back-end SQL data in Windows Explorer.