Best Practices and Pitfalls to Avoid - Sitecore

Creating and Querying Items

General




Absolute vs. Relative Paths


var items = Sitecore.Context.Database.SelectItems("/sitecore/content/MyStore/Orders/*");

It is instead better to query that folder by its ID, then query its contents via a relative query. This way, the content can be rearranged within the Sitecore hierarchy without breaking the code.

var folder = Sitecore.Context.Database.GetItem(new Sitecore.Data.ID(folderGuid));
var items = folder.Axes.SelectItems("*");


Security

User Domains

Although you can write code to create a Sitecore user without specifying a domain, the Sitecore Admin UI (Security Editor, Access Viewer, etc.) won't work for such a user. You are therefore strongly encouraged to create users within a domain. This effects two areas of your code: the Login page and the User Registration page. See the Sitecore Security Overview page for more details.