Dav.AspNetCore.Server is a WebDAV implementation based on RFC 4918. It allows you to easily integrate DAV functionality into your ASP.NET Core application. Some architectural concepts where taken from NWebDav but where greatly improved upon.
- RFC 4918 compliant
- Supports any registered authentication, but also ships with Basic and Digest authentication
- Extensible infrastructure which lets you design your own store or locking providers
Install Dav.AspNetCore.Server via dotnet cli or through the package manager provided by your favorite IDE.
> dotnet add package Dav.AspNetCore.Server
In order to enable WebDAV in your project you need to add the following service registrations and middlewares:
using Dav.AspNetCore.Server;
using Dav.AspNetCore.Server.Store;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddWebDav(davBuilder =>
{
// add the local files store with a mount point
davBuilder.AddLocalFiles(options =>
{
options.RootPath = "/tmp/";
});
});
var app = builder.Build();
app.Map("/dav", davApp =>
{
davApp.UseWebDav();
});
app.Run();
There are different types of locking implementations available. If you need something simple you can start out with the in memory lock implementation:
builder.Services.AddWebDav(davBuilder =>
{
[...]
davBuilder.AddInMemoryLocks();
});
In case you need something more distributed you can check out the other sql based implementations:
Storing (custom) properties is a crucial part of DAV. To start accepting properties you need to configure a property store. Like previously mentioned in the locking section there are different implementations available:
builder.Services.AddWebDav(davBuilder =>
{
[...]
// there will be a xml file containing properties for each resource made available
// it's important to not expose this folder
davBuilder.AddXmlFilePropertyStore(options =>
{
options.AcceptCustomProperties = true;
options.RootPath = "/tmp_meta/";
});
});
You may ask: what exactly is a "custom" property; A custom property is a property not made available by the
dav resource itself, it can be arbitrary data. Since this example uses the local file store, all properties
are computed and thus can't be changed which only leaves us with adding additional properties. On different
dav resources with normal properties (not protected and not calculated) you can change them without having
AcceptCustomProperties = true
.
Different sql based implementations are available here:
Feel free to open issues or submit pullrequests.