Question

I have an existing MVC3 application which allows users to upload files and share them with others. The current model is that if a user wants to change a file, they have to delete the one there and re-upload the new version. To improve this, we are looking into integrating WebDAV to allow the online editing of things like Word documents.

So far, I have been using the .Net server and client libraries from http://www.webdavsystem.com/ to set the website up as a WebDAV server and to talk with it.

However, we don't want users to interact with the WebDAV server directly (we have some complicated rules on which users can do what in certain situations based on domain logic) but go through the previous controller actions we had for accessing files.

So far it is working up to the point where we can return the file and it gives the WebDAV-y type prompt for opening the file.

The problem is that it is always stuck in read-only mode. I have confirmed that it works and is editable if I use the direct WebDAV URL but not through my controller action.

Using Fiddler I think I have found the problem is that Word is trying to talk negotiate with the server about the locking with a location that isn't returning the right details. The controller action for downloading the file is "/Files/Download?filePath=bla" and so Word is trying to talk to "/Files" when it sends the OPTIONS request.

Do I simply need to have an action at that location that would know how to respond to the OPTIONS request and if so, how would I do that response? Alternatively, is there another way to do it, perhaps by adding some property to the response that could inform Word where it should be looking instead?

Here is my controller action:

public virtual FileResult Download(string filePath)
{
    FileDetails file = _fileService.GetFile(filePath);
    return File(file.Stream, file.ContentType);
}

And here is the file service method:

public FileDetails GetFile(string location)
{
    var fileName = Path.GetFileName(location);
    var contentType = ContentType.Get(Path.GetExtension(location));
    string license ="license";
    var session = new WebDavSession(license) {Credentials = CredentialCache.DefaultCredentials};
    IResource resource = session.OpenResource(string.Format("{0}{1}", ConfigurationManager.AppSettings["WebDAVRoot"], location));
    resource.TimeOut = 600000;
    var input = resource.GetReadStream();
    return new FileDetails { Filename = fileName, ContentType = contentType, Stream = input };
}

It is still very early days on this so I appreciate I could be doing this in entirely the wrong way and so any form of help is welcome.

Was it helpful?

Solution

In the end it seems that the better option was to allow users to directly talk to the WebDAV server and implement the authentication logic to control it.

The IT Hit server has extensions that allow you to authenticate against the forms authentication for the rest of the site using basic or digest authentication from Office. Using that along with some other customisations to the item request logic gave us what we needed.

OTHER TIPS

This is exactly what i did for a MVC 4 project.

https://mvc4webdav.codeplex.com/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top