Skip to content
This repository has been archived by the owner on Feb 14, 2022. It is now read-only.

Untrusted or expired SSL certificates

DecaTec edited this page May 18, 2017 · 5 revisions

The Portable WebDAV Library can be used with WebDAV servers using a SSL certificate (HTTPS). However, an exception will be thrown if these certificates are untrusted or expired. This is a common scenario when using so called self signed certificates.

It is up to the application/app using the Portable WebDAV Library to handle these certificate errors.

See this example when untrusted/expired certificates are used:

// Use the ServicePointManager.ServerCertificateValidationCallback to ignore certificate errors.
// This call should be done before trying to access any WebDAV resources, otherwise an exception will be thrown.
ServicePointManager.ServerCertificateValidationCallback += (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) =>
{
    // Specify which certificate errors should be ignored.
    if (sslPolicyErrors == SslPolicyErrors.RemoteCertificateNotAvailable)
        return true;
    else
        return false;
};

// The base URL (HTTPS) of the WebDAV server.
var webDavServerUrl = @"https://www.myserver.com/webdav/";

// Specify the user credentials.
var credentials = new NetworkCredential("MyUsername", "MyPassword");

// Create a WebDavSession with the HttpBaseProtocolFilter.
using (var webDavSession = new WebDavSession(webDavServerUrl, credentials))
{
    var items = await webDavSession.ListAsync(@"MyFolder/");

    foreach (var item in items)
    {
        // Handle the response (list of WebDavSessionListItems).
    }
}
Clone this wiki locally