CalDAV / CardDAV Server Example, C#
CalDAV / CardDAV example is a calendaring server and address book server that runs on IIS or IIS Express. It is validating user credentials against Windows Active Directory or local Windows accounts and can be configured to use Basic, Digest or Integrated Windows Authentication. All calendar and address book data are stored in the file system.
To run this example you will need:
ASP.NET 3.5 or ASP.NET 4.x on Windows Server 2012, Windows Server 2008, Windows 8, Windows 7 or Windows Vista.
NTFS file system.
For simplicity of evaluation Visual Studio 2013 or Visual Studio 2012 are recommended. This sample does not support Visual Studio 2010.
Note while MSI installer and WebDAV Wizards for Visual Studio require .Net Framework 2.0 or 3.0 or 3.5 to be installed, the Server Engine itself and samples can run .Net Framework 3.5 - 4.5.1. If you do not have .Net 2.0-3.5 installed on your machine you can download the .zip archive with samples and server dll and unpack them manually.
Installation and Configuration
By default CalDAV / CardDAV Server example is installed to C:\Users\<UserName>\Documents\IT Hit\WebDAV Server Engine\vX.X.X\Samples\CalDav\ folder.
Setting the License
To run the example, you will need a valid IT Hit WebDAV Server Engine License. You can download the license here. 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.
Place the license file in the root folder of the CalDAV Example (\Samples\CalDav\).
The files are stored in the file system in \Samples\CalDav\App_Data\WebDav\Storage\ folder. You can change the storage location in RepositoryPath tag in web.config.
Running the Sample from Visual Studio
If you have Visual Studio, the simplest way to run the sample is to run it from Visual Studio. In this case, you do not need to configure the web application in IIS.
Run the Visual Studio with Administrative privileges (required for IIS Express impersonation, see below) and open the project. In the project properties, you will see that this sample is configured to use Windows authentication:
Run the project from Visual Studio. The web browser will be opened and request for authentication. You will provide your Windows account credentials:
This example stores calendars and address books as folders in the file system. During first login, the ProvisioningModule will create several calendars and address books. It will also grant the logged-in user permissions in the file system to access user home folder. The sample server will display the path to each calendar and address book on a default page that is shown when accessing any folder on a server:
To examine your repository click on “Examine your server content with IT Hit Ajax Browser” link:
Note that to be able to see the above folder structure, the user that you used to log-in to the website must have List Folder Contents permissions in your \Samples\CalDAV\App_Data\Repository\ folder.
On the above screenshot, you can see the several .ics files. Each file represents a calendar event while the folder itself represent calendar. These files were created by the Calendar client, you would not find them before you connect with a CalDAV client and create events.
Note that ACL folder and its content is not present in the file system, it comes from your Active directory or local Windows accounts.
To create initial calendars and address books as well as for other file system operations this sample is using impersonation. In case you run your project in IIS Express and log-in to your web application as the user that is different from the one running Visual Studio (and IIS Express) the impersonation will fail. If after the log-in you get the error, consider the following:
- The account under which your application is running does not have enough permissions to impersonate the logged-in user. Usually, this is because you are running your application in IIS Express and Visual Studio is started with non-administrative privileges. Restart Visual Studio as Administrator.
- Your web application does not have enough permissions in the file system to create the required folders, access web.config file or grant permissions on the file system folder for the logged-in user during the first login. In case, your application is running in IIS read ‘Deploying your CalDAV / CardDAV Server to IIS’ section and make sure the user has enough permissions in the file system.
Configuring Email Notifications
When you add one or more Attendee to the meeting the CalDAV sample implementation will notify meeting attendees by sending email messages. It will also notify attendees about meeting updates and cancelations. The sample is using SMTP to send email messages, which is configured in web.config. One of the simplest ways to test email notifications is to configure Google SMTP server:
<configuration> ... <system.net> <mailSettings> <smtp from="firstname.lastname@example.org" deliveryMethod="Network"> <network defaultCredentials="false" host="smtp.gmail.com" port="587" userName="email@example.com" password="mygmailpassword" /> </smtp> </mailSettings> </system.net> </configuration>
Note that smtp\from attribute must match your gmail e-mail and match the network\userName attribute.
In case the SMTP is incorrectly configured the server will log the error to WebDAVLog.txt file. You can find such errors searching for “SmtpException” string in the log.
Access Control List
This sample provides ACL implementation that is mapped to Windows accounts. User credentials will be validated against Active Directory or local Windows accounts. Below you can see ACL users and groups mapped to Windows accounts:
These sample contains a broad ACL implementation that is not required in many cases. You can truncate ACL implementation removing functions for manipulating users and groups leaving a read-only implementation of truncated browsing functions.
Deploying your CalDAV / CardDAV Server to IIS
Follow the steps below to deploy the CalDAV/CardDAV sample in IIS 7 and later:
Configure a new website in IIS as described in Configuring Your WebDAV Website in IIS article.
Give Full Control permissions to the identity under which your web application is running in \Samples\CalDav\App_Data\WebDAV\Repository\ folder. In case you have set up ApplicationPoolIdentity in step 1 and named your pool DavAppPool, give Full Control permissions to IIS APPPOOL\DavAppPool account:
When user accesses your CalDAV server for the first time, the ProvisioningModule will create initial calendars and address books in file system and grant permissions to the logged-in user on his home folder in file system.
Configure Windows Authentication as described in Configuring Windows Authentication article.
Optionally, to be able to connect with iOS iCal and iOS Contacts applications faster on iPhone and iPad, configure SSL with a self-signed certificate on default SSL port 443, as described in Configuring SSL on your WebDAV Server Running in IIS.
Enabling Apple iCal Sharing Support
The CalDAV / CardDAV sample provides IAppleCalendar interface implementation which allows you to share calendar using Apple iCal ‘Share With’ feature as well as to make calendar public:
The sample code that implements Invite and SharedBy properties in CalendarFolder.cs that enables this feature is commented-out. To see how it works, uncomment the code and recompile the project.