.NET Server

Cross-platform ASP.NET Core WebDAV Server Sample with Microsoft SQL Back-End

In this article

Cross-platform ASP.NET Core WebDAV Server Sample with Microsoft SQL Back-End

This is a cross-platform WebDAV server sample with Microsoft SQL back-end that stores all data in a file system and runs as ASP.NET Core web application on Windows, OS X and Linux. The sample keeps all data including locks, file content and custom properties in the Microsoft SQL Server database. The WebDAVServer.NetCore.SqlStorage example is a fully-functional WebDAV server that can be used to open, edit and save Microsoft Office documents directly on a server, without download/upload steps. You can use it to access documents using Microsoft Mini-Redirector/Web Folders, Mac OS X Finder or any other WebDAV client. This sample is anonymous by default but is provided with sample Basic and Digest authentication middle-ware.

This sample is provided with a sample web page that demonstrates WebDAV Ajax Library integration that is used to open documents from a web page, list server content and navigate folders structure.

This sample is provided as part of the IT Hit WebDAV Server Engine v5 and later and is published to GitHub and to NuGet. For a legacy, SQL Storage sample provided with IT Hit WebDAV Server Engine v4.5 and earlier based on HttpHandler see this article.

Prerequisites

  • .NET Core 3.1 or later version on Windows, OS X or Linux.
  • Microsoft SQL Server Express LocalDB or Microsoft SQL Express or Microsoft SQL Server 2019 / 2016 / 2014 / 2012 / 2008 / 2005.

Running Sample Using Command Prompt

The instructions below describe how to install a sample from NuGet and are universal for Windows, OS X and Linux:

  1. Install .NET Core. Follow instructions on this page to install Microsoft .NET Core on Windows, OS X, and Linux: https://www.microsoft.com/net/core
  2. Install NuGet client tools: https://docs.microsoft.com/en-us/nuget/install-nuget-client-tools
  3. Create a project folder, for example,/WebDAVServer/, and navigate to that folder in console.
  4. Get the project from NuGet: 
    nuget install WebDAVServer.SqlStorage
  5. Navigate to the project folder, where the .scproj file file is located:
    cd WebDAVServer.FileSystemStorage.<version>
  6. Restore dependencies:
    dotnet restore
  7. Build the project:
    dotnet build
  8. Run the project:
    dotnet run

Now your server runs on http://localhost:5000. Open the web browser with this URL and you will see the web page that lists folder content on your server and provides an edit button/link for opening each file from the server using WebDAV Ajax Library. You can also run the Ajax Integration test to find if your server is running correctly. To upload documents, create folders, copy and move files, manage custom properties, etc you can use the Browse Using Ajax File browser button.

Setting the License

To run the example, you will need a valid IT Hit WebDAV Server Engine License. You can download the license in the product download area. Note that the Engine is fully functional with a trial license and does not have any limitations. The trial license is valid for one month and the engine will stop working after this. You can check the expiration date inside the license file. Download the license file and specify it's content in License field under DavEngineOptions in appsettings.webdav.json file.

You can also run the sample without explicitly specifying a license for 5 days. In this case, the Engine will automatically request the trial license from IT Hit website https://www.webdavsystem.com. Make sure it is accessible via firewalls if any. After 5 days the Engine will stop working. To extend the trial period you will need to download a license in a product download area and specify it in appsettings.webdav.json

Storage location

When you run the sample for the first time it will find a default database Microsoft SQL instance and runs the script from DB.sql to create a new WebDAV database. It will also populate it with sample files and folders. You can also create the database manually running the DB.sql on the required Microsoft SQL instance and updating the connection string in appsettings.webdav.json file.

Authentication

This sample is provided with Basic and Digest authentication middle-ware. By default the authentication is disabled and the sample is anonymous. To enable Basic or Digest authentication uncomment the UseBasicAuth() or UseDigesAuth() calls inside Configure() method in Startup.cs.

For the sake of simplicity, credentials are stored in appsettings.webdav.json file.

Microsoft Office on Windows and OS X as well as Windows Shell (Web Folders / mini-redirector), requires secure SSL connection when used with Basic authentication. Microsoft Office will fail to open a document via an insecure connection with Basic authentication. For a workaround please see the following articles:
- In the case of MS Office on Windows: You cannot open Office file types directly from a server that only supports Basic Authentication over a non-SSL connection with Office applications.
- In the case of MS Office on Mac OS X: You cannot open Office for Mac files directly from a server that supports only Basic authentication over a non-SSL connection.

See Also:

Next Article:

Cross-platform ASP.NET Core WebDAV Server Sample with File System Back-End