Friday, 30 June 2017

GetItem method returns null when Item Name is like GUID

Recently, we upgraded our CMS to Sitecore XP 8.2 Initial Release, we started facing weird issue. The fonts where not loading on pages. When we started digging the issue, we found a pattern. The issue was not for all font files but only for those having GUID like names

E.g. 054c9659-429a-4553-b54e-7db2eedb542a.woff2

So, we tried to reproduce and debug the same in local and we came to know that while trying to get item by using GetItem(string path) method, it returns null.

Then we tried to replicate the same in clean sitecore installation. We created an Item under /sitecore/content/Home/ and named it 054c9659-429a-4553-b54e-7db2eedb542a

Thursday, 22 June 2017

Sitecore Cache Manager Tool


Sitecore provides very powerful caching mechanism. Mainly there are three types of cache layers, Items cache, Data cache and Prefetch cache.

Other than above caches, there are many other different caches sitecore maintains in memory. And the number dramatically increases if you have multisite instances.

Read more about sitecore caches in detail: http://sitecoreblog.patelyogesh.in/2013/06/how-sitecore-caching-work.html

Caching issues on CD servers after publishing is common when you are dealing with horizontally scaled Sitecore environment and we were no exception. Recently, we started facing this issue frequently.

Meanwhile you are troubleshooting the caching issue as it might not be a task of a day or two - sometimes you may have to wait for weeks for it to reproduce and collect all relevant data - Cache Manager tool is must have tool for all Sitecore developers dealing with large instances.

Sitecore provides a nice caching tool, Cache.aspx,  in built. (you may find it at /sitecore/admin/cache.aspx) this tool is helpful when you are dealing with small instances of sitecore where your entire cache size is not more than 500 MB, because this tool has a button to clear ALL the caches on a single hit.

Sunday, 11 June 2017

Sitecore: Add Custom Standard Values Tokens


Sitecore provides below seven out-of-the-box standard values tokens

    $name: The name for the new item entered by the user
    $id: The ID of the new item
    $parentid: The ID of the parent of the new item
    $parentname: The name of the parent of the new item
    $date: The system date in yyyyMMdd format
    $time: The system time in HHmmss format
    $now: The system date and time in yyyyMMddTHHmmss format

Although in most cases you may fulfill your requirements using above tokens, but sometimes, you may need to create additional tokens.

For example, showing user full name who created the item.

This can simply be done by extending Sitecore's master variable replacer class,  Sitecore.Data.MasterVariablesReplacer

Tuesday, 23 May 2017

Sitecore Integrated Icon Finder Module


If you are working on Sitecore then you must be aware that setting a proper contextual icon for a content item is usually a good practice as it helps content authors as well as developers to easily identify the context of an item or the purpose the page is created for.

Sitecore provides a rich set of icons in built. There are around a thousand icons we can search from, to select a contextual icon for an item. But there is no search feature available out of the box, so selecting a right icon seems very tedious process sometimes.

Monday, 26 October 2015

Register/Deregister EC2 Servers under ELB using AWS .NET Toolkit

I have been working with AWS toolkit for some time in last week. I prepared some tools to automate our infra team tasks and for our internal development and testing purpose.

Here I will show you how to register/de-register EC2 instances with Elastic Load Balancer programmatically using AWS .NET toolkit.

First get your awsSecretAccessKey and awsAccessKey,


1
2
 string awsSecretAccessKey = ConfigurationManager.AppSettings["awsSecretAccessKey"];
 string awsAccessKey = ConfigurationManager.AppSettings["awsAccessKey"];

Note: The user account you use here for Secret Key and Access Key must have full access to EC2 service of AWS

Create EC2 Client,


1
 var client = AWSClientFactory.CreateAmazonElasticLoadBalancingClient(awsAccessKey, awsSecretAccessKey, RegionEndpoint.USWest2);

Make sure you specify correct RegionEndPoint where your EC2 instances exist. Here I have used USWest2 region end point.

Thursday, 20 August 2015

Automate Cloudfront Cache Invalidation Using AWS .NET Toolkit

Amazon CloudFront is a content delivery web service to give developers and businesses an easy way to distribute content to end users with low latency and high data transfer speeds.

Amazon Cludfront has a number of edge locations worldwide, when your application target audience is scattered worldwide then Amazon Cloudfront is a good choice for caching your files and contents to give high throughput and low latency. Let say, if someone is accessing your application from east zone of USA then your contents will be delivered by one of the cloudfront edge servers located in USEast.

Your files which got cached on cloudfront edge locations will be automatically invalidated as per the default Cache Timeout set in request header. But sometimes you may forcefully want to clear files from Cloudfront cache prior to the actual Cache Timeout.

Wednesday, 1 July 2015

Sitecore : Datetime Field with Timezone

Working with Date Time and Timezones is always headache. Recently we faced issue with calendar events generated by our sitecore application in different regions. The start date and end date in generated ICS file was failing to show exact date time specific to end user because of the difference in timezones.

Why that happened?

Curretly there is no mechanism in sitecore to store date and time in different timezones. It simply considers the server timezone - on which the sitecore instance runs - and stores date time accordingly.  So, to make datetime field independent of any specific timezone (more specifically - server timezone) , we needed a custom field that stores UTC (Universal Coordinated Time) , a globally unique datetime, as raw value and presents timezone specific date and time to the content authors.

Note: We can easily do conversion of UTC to any timezone and visa versa, with .NET globalization API


How this prototype works?

Here is how the new field looks to content authors.


This is what sitecore stores in backend.


You can notice the raw value is the UTC equivalent of the IST time content authors can see. And this is the secret of this field :)

You might be wondering from where the the timezone India Standard Time is coming??
 -  In our application, we have separated all settings from actual content items, and those settings are globally applicable to entire site (something like AppSettings in .net application)

-  So here the timezone IST is coming from site level settings, which looks like this



-  Based on above selection, only the display date and time will change, but the raw value will remain same.