.NET Server

Creating WebDAV Server with Cookies Authentication

In this article

Creating WebDAV Server with Cookies Authentication

This article describes how to create a WebDAV server with pure cookies authentication and open documents using WebDAV Ajax Library from a web page.

Microsoft Office, LibreOffice and WPS Office require persistent authentication cookie (cookie with expiration date) to open documents from a web page. They can NOT open documents from a website with a session cookie (without expiration date). Typically you have to check the "Keep me logged-in" or "Remember me" checkbox on your website when logging-in to make cookies persistent.

Creating an ASP.NET Web Application in Visual Studio

First, we will create an ASP.NET Core Web Application with cookies authentication. You can select the ASP.NET Core Web Application, or the ASP.NET Web Application (.NET Framework), or the Blazor Server App. 

Create an ASP.NET Web Application in Visual Studio

You can select the Razor type of project, MVC project, or Web Forms project.

Than got to the Change Authentication.

Select Web Forms, MVC or both. Go to Change Authentication.

Select the "Individual User Accounts" option.

Select Individual User Accounts option in Change Authentication dialog

Adding WebDAV with Cookies Authentication

On this step, you will be using IT Hit WebDAV Server Engine for .NET wizards for Visual Studio to add WebDAV to your project. The WebDAV wizards are automatically installed with WebDAV Server Engine for .NET SDK.

Select "Add WebDAV Server Implementation" option in project context menu:

Select Add WebDAV Server Implementation option in context menu

You can keep all options to default except for the Authentication step. Select the "Cookies/Forms" option on the Authentication step.

Make sure to uncheck the Basic, Digest, and MS-OFBA options! These options generate Mixed authentication which will make your cookies auth testing more difficult.

Select WebDAV Cookies authentication option. Make sure to uncheck Basic, Digest and MS-OFBA!

Updating MyCustomHandlerPage.aspx Page to Pass the Authentication Cookie

This step is required only with IT Hit WebDAV Server Engine for .NET v6.1.4235 and earlier. In v6.1.4279 and later versions the code generated by the Add WebDAV Server Implementation wizard adds DavProtocolEditDocument() with proper parameters automatically if Basic, Digest and MS-OFBA options are unchecked on the Authentication step.

Update the WebDAV Ajax Library сode on MyCustomHandlerPage.aspx that opens the document with the associated application and opens OS file manager. You will pass the authentication cookie name (.AspNet.ApplicationCookie) into all WebDAV Ajax Library DocManager functions:

Replace the сode for "Edit" command:

This code is part of WebDAV Server File System sample provided with IT Hit WebDAV Server Engine for .NET

                            
                        

with:

This code is part of WebDAV Server File System sample provided with IT Hit WebDAV Server Engine for .NET

                            
                        

Replace the сode for "Open With" command:

This code is part of WebDAV Server File System sample provided with IT Hit WebDAV Server Engine for .NET

                            
                        

with:

This code is part of WebDAV Server File System sample provided with IT Hit WebDAV Server Engine for .NET

                            
                        

Replace the code for "Open OS File Manager" command:

This code is part of WebDAV Server File System sample provided with IT Hit WebDAV Server Engine for .NET

                            
                        

with:

This code is part of WebDAV Server File System sample provided with IT Hit WebDAV Server Engine for .NET

                            
                        

You can find more about the above JavaScript functions in Opening MS Office and other Docs from a Web Site with Cookies Authentication article.

Running Your Web Application

Run your web application and create a new account. Note that WebDAV wizard has changed the default start URL in your application in Visual Studio, so you are redirected directly to the log-in page.

ASP.NET web application - Create new account

After creating a new account you are logged-in with a session cookie (without expiration date). To open MS Office documents you need to be logged-in with persistent cookie (with expiration date). To do this close the web browser and start your application again.

Go to the log-in page and log-in with the "Remember me" checkbox:

Log-in with "Remember me" checkbox to create a persistent authentication cookie, that is required to open MS Office docs from a web page.

Note that you can program your website to always set a persistent cookies and remove the Remember me checkbox.

After logging-in you will be redirected to your default WebDAV page specified in WebDAV wizard (/DAV/ by default). Now you can open documents for editing and save them back directly to the server.

Make sure you install the protocol application supplied with WebDAV Ajax Library and confirm the web browser extension activation. The web browser extension is used to pass cookies and must be activated.

Install the Edit Document Opener protocol application and activate the web browser extension. Now you can open documents from a web page.

Next Article:

Configuring NTLM Authentication and Avoiding the Login Prompt