Book Image

Sitecore Cookbook for Developers

By : Yogesh Patel
Book Image

Sitecore Cookbook for Developers

By: Yogesh Patel

Overview of this book

This book will get you started on building rich websites, and customizing user interfaces by creating content management applications quickly. It will give you an insight into web designs and how to customize the Sitecore architecture as per your website's requirements using best practices. Packed with over 70 recipes to help you achieve and solve real-world common tasks, requirements, and the problems of content management, content delivery, and publishing instance environments. It also presents recipes on Sitecore’s backend processes of customizing pipelines, creating custom event handler and media handler, setting hooks and more. Other topics covered include creating a workflow action, publishing sublayouts and media files, securing your environment by customizing user profiles and access rights, boosting search capabilities, optimising performance, scalability and high-availability of Sitecore instances and much more. By the end of this book, you will have be able to add virtually limitless features to your websites by developing and deploying Sitecore efficiently.
Table of Contents (20 chapters)
Sitecore Cookbook for Developers
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Initializing hooks to subscribe events to prepare an audit trail


Sitecore hooks provide you with an interface to invoke custom logic on system initialization before any HTTP web request is served. You can use hooks to subscribe to events dynamically, configure memory and health monitoring, switch MediaProviders and LinkProviders, interpret URLs, and much more.

In this recipe, you will learn how to use hooks to subscribe events to prepare an audit trail of different item operations such as create, delete, move, and others. You will also learn how to override MediaProvider using hooks.

How to do it…

We will first create an event handler class where we will create some event handling methods:

  1. In the SitecoreCookbook project, create an event handler AuditTrailEventHandler class in the Handlers folder, and create a WriteLogs property in it:

    public bool WriteLogs { get; set; }
  2. Create the OnItemCreated() and OnItemDeleted() event methods as follows:

    public void OnItemCreated(object sender, EventArgs...