Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
Experience Sitecore! | All posts by martin

Experience Sitecore!

Martin Miles on Sitecore

Software every good Sitecore developer should be aware of

Got your top-spec developer's machine with Visual Studio installed, an instance of SQL Server with databases and Sitecore running on your IIS? So far, so good. You may now start working with platform. However, for real productivity you may need certain extras we'll now go through.

  1. Sitecore Rocks
  2. Team Development for Sitecore
  3. Reflector
  4. dotPeek
  5. Sitecore Instance Manager
  6. Luke
  7. RoboMongo

1. Sitecore Rocks
Today Rocks became a mature plugin allowing unbelievably wide range of Sitecore tasks and activities right from your Visual Studio. It grew from an idea of being able to manipulate Sitecore tree right from Solution Explorer (without permanent switches to browser and back), but with time acquired a mass of killing features, covering all aspects of working with Sitecore. Let's just name few of them:

  • navigate Sitecore tree within VS, create and edit items, layouts, renderings, templates (and their hierarchy), standard values, and also manage Media Library
  • built query analyzer (that was removed from 7.5 into a SPEAK component) that allows to operate all types of queries
  • troubleshooting features addressing tracing and debugging as well as log manager
  • view scheduled jobs
  • all about publishing
  • administration functions to perform maintenance for database, indexes etc; view resulting (after patches) web.config file
  • ability to read Lucene indexes, navigate documents and see field values, terms etc.
  • perform real-time search and replace globally from Query Analyzer
  • view history table
  • everything about creating and managing packages
  • create pipelines
  • all about caching
  • plugin repository to extend functionality further more by applying multiple plugins
Impressive list? But how to manage such wide functionality and not get lost?
Luckily, there is handy Commandy feature that allows you quickly search and access all the features just by a hotkey!

Links:
Sitecore Rocks on Visual Studio Gallery
Documentation page
28 days with Sitecore Rocks technical blog



2. Team Development for Sitecore - TDS
Another Visual Studio extension worth of several separate articles. It is manly focused on resolving troubles of having sitecore itens and sitecore code seperately, so it solves the issue by serializing items and keeping them in source control along with the code so that multiple people working at the same solution can have solid commits and fair versioning policy.

TDS can help you with many other handy tasks like item merging, code generation, packaging and auto deployment, config transformation and others. If you follow the link below - you'll get ver y self-descriptive home page explaining what exactly and how TDS does.

Links:
TDS download page


3. Reflector
Not Sitecore specific, but .NET-wide, Reflector is a tool that decompiles and reveals the code hidden in DLL libraries (if not obfuscated) and allows browse it and drill into system DLLs as well. We use it widely with Sitecore as Sitecore is not allways specific about ints internal architecture in official documentation, but knowing internals is the must for any good developer. A good example can be pipelines architecture - it is not quite documented (if at all) while from time to time one would need to override default behavior or add additional processors. Without knowing what exactly original code does that becomes not possible.

Links:
Reflector download page


4. dotPeek
One more .NET decompiler (which is free, unlike previously mentioned Reflector) have recently joined the market. Apart from doing decompiling job, it has several useful features, like ability to generate PDB files out of DLL, that makes possible debugging of external DLLs in Visual Studio.

  • Exporting decompiled code to Visual Studio projects
  • Support downloading code from source servers or PDB files generation
  • Quick jump to a type, assembly, symbol or type member
  • Effortless navigation to symbol declarations, implementations, derived and base symbols, and more
  • Accurate search for symbol usages with advanced presentation of search results
  • Overview of inheritance chains
  • Syntax highlighting and complete keyboard support
Please read another blog post Debugging and Inspecting Sitecore Libraries to how you can easily do that with dotPeek.
Links:
dotPeek official home page

5. Sitecore Instance Manager - SIM
I have a separate article about SIM, so please read that if you are not yet familiar with this brilliant tool. If briefly, SIM simplifies and automates a process of installing an instance of Sitecore (any version you may have in your local repo) to just few clicks, automatically sets up database and configs, installs additional packages and modules on top of instance and keeps multiple useful housekeeping links (to hosts, configs, iis, database etc.) in one place.

Links:
Sitecore Instance manager on Sitecore Marketplace
My previous article about Sitecore Instance Manager in this blog


6. Luke
Luke.NET is a tool to browse Lucene indexes, see the documents, fields and terms, try writing queries against index and see index physical structure. This functionality is partly covered with Rocks, as described above.


Links:
Luke page on CodePlex


7. RoboMongo
For everyone who is after Sitecore 7.5 (and later) and is working with xDB, Robomongo may seem quite handy. What is does is allows to see what you have in your Mongo instance. RoboMongo embeds the same JavaScript engine that powers MongoDB's mongo shell. It means that you can reuse your existing skills of MongoDB shell in RoboMongo. It provides you with syntax highlighting, auto-completion, different view modes (text, tree, custom), and more.There will be a separate article about it coming shortly.


Links:
Official page

IIS URL Rewrite module - few SEO tricks



1. Canonicals - do 301 permanent redirect (this also works with HTTPS).






    

  


2. Rewrite URL lowercase - one more rewrite rule aiming SEO improvement.






3. Append trailing slash - this is another SEO (sometimes arguable) improvement. It is believed that having trailing slash on your URLs (except when it deals with file names for sure) will improve search engines ranking.










4. Query string rewrite - the example of extracting query string parameters and rewriting it in your own manner






    



5. Redirect to HTTPS - forcely redirect all non-secure request to HTTPS









6. Prevent image hot-linking - disallow strangers of reusing images hosted on your website in order to protect them and traffic.










The quickest acceess to Layout Details dialog of Presentaion Details

This post going to be a quicke one. One of the most frequent screens I have to deal with in Sitecore is Layout Details dialog of Presentation Details:


I thought once, why not just to have the link to it from item's Context Menu? Sounds good, but, foirst of all, what is context menu?

Context Menu is just a set of Sitecore items under /sitecore/content/Applications/Content Editor/Context Menues/Default folder within core database. Each child item (except dividers) is derived from Menu Item template. The most interesting field there is Message - its value stores is nothing but just a Sitecore command with a parameter of current item (as all that happens in item's context).


Just want to remind - Sitecore commands are defined at <web_root>\App_config\Commands.config file, you may freely use any of them that start with item: (but not limited to that).

So, the only thing we need to do is to create an item under /sitecore/content/Applications/Content Editor/Context Menues/Default folder, and set its message to item:setlayoutdetails and that's it. Also you may configure Display name and the Icon to be shown next to that label within context menu (something like Applications/32x32/document_gear.png)


As soon as you return to master database, you'll get new context menu shortcut working:


This trick works on all versions of Sitecore. For lazy guys - here's a package for download that will do exactly the same - create Set presentation item for you within core database.

Hope this helps!


Debugging and inspecting Sitecore libraries

Debugging requires symbol files to present within a bin directory along. You have Sitecore libraries, and they are not obfuscated, so you may decompile and inspect the original code using various tools like Reflector. But you need PDBs to be able to to debug those libraries, for example perform step Into, watch and modify locals, set breakpoints and similar actions.

How to generate PDB files from assembly? There is a great (and free!) tool from JetBrains called dotPeek. As soon as you download and install it, you will be able to generate PDB from any non-obfuscated assembly with it. To do that, first specify the location where PDB are kept:


Also allow to debug "not just my" code -this will allow debugger to step into methods that are stored in other referenced libraries, of course of you have their PDBs in symbols folder, as set on previous step.


Now with dotPeek we'll generate PDB under the same path previously set in Visual Studio where it will seek for symbols. Open library in dotPeek, right click its context menu and select Generate PDB, as on a screenshot below:


Remember path should be the same:


Congratulations! Now you can debug that DLL and get more understanding of how Sitecore works internally especially when sometimes you may need to override its functionally and implement your custom logic based on that.

Important! On the recent versions of Sitecore, especially Sitecore 9 or newer you may experience troubles with stepping in withing Sitecore.Kernel library. That happens due to that with time it has been more and more rewritten to rely on Sitecore.Abstractions so you will need to generate PDBs and de-optimize that one as well.

You are now able to debug the code, step into the functions and investigate the logic as the code runs. But you may not still get the entire experience as if you were debugging your own code - due to optimization. To overcome optimization you need to start Visual Studio as Administrator with setting a specific environment variable:
set COMPLUS_ZapDisable=1
cd /d "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE"
start devenv.exe
exit
Next, for each DLL you are about to explicitly disable optimisation, you need to accompany with a *.ini file having the same name and the following instructions (example for Sitecore.Kernel.ini):
[.NET Framework Debugging Control] 
GenerateTrackingInfo=1 
AllowOptimize=0
Finally, as ReSharper is your permanent friend, you'll find the most convenient way to inspect the code by using its Assembly Explorer:

Hope this helps!

How websites are resolved with Sitecore - the essentials

What actually happens when you type website URL in browser and how is your request factually served in sitecore. We are going to use www.site.com as the URL for our example. This is simplified version where only most important steps are covered.

First of all, as you hit this URL in browser's address bar, it retrieves IP address by the host name from DNS server. Then it creates request to IP address resolved with host name (www.site.com) in HTTP header. There may be multiple traffic managers / load balancers on the route to the server, but eventually request gets to that IP address to the specified port (as we use normal HTTP, then the port is default 80).

On the server computer there should be specific software running and listening to that port (80) otherwise request will fail. In our scenario, that is the Microsoft IIS web server. Below are two most important IS configuration screens:


On the first screenshot you see Site Bindings screen that binds exact website within current IIS instance to specific port and hostname (if set). There can be multiple website hosted within same IIS instance, so you we usually vary them by hostname / port combinations. The example above shows that all requests to port 80 with the hostname www.site.com would be served by current website. Second record shows that all requests to port 443 (which is default to HTTP) would be served by the same site as well.


The second screenshot assigns our website www.site.com to a folder on a disk drive which becomes a web root for our site.

Root of the website should have a configuration file called web.config, that may be split and overridden in subfolders and that itself overrides global web.config and machine.config files with default settings. Every sitecore-based website contains <sitecore> node in the configuration file, that is where all sitecore settings are defined, including <sites> node that specifies all the websites per current Sitecore instance.


Important to note that sites are determined by "first match" principle, so order is critical. If you look at our www.site.com record - you'll notice that it specifies hostname - all requests matching that name will be served by this site. Other setting set what database is used for particular site (name should match database name from connection string), what is starting sitecore tree node within that database - factual page item that is being returned. There are also html caching setting, sitecore domain name for the site, etc.

The rest of request to current Sitecore instance, that do no math our host name pattern will be served by site called "website", it does not have hostName specified, so it will serve everything else and return /sitecore/content/home item.

Let's assume the site has been published from master database to web database, as per configuration. Here's below how sitecore tree looks like in Sitecore Content Editor:


Our website's home item (selected) is called SiteCom and it will return the page with "www.site.com"in title. Let's see the browser:


Here we done. That is our www.site.com landing page loaded!


Advanced topic: How to host several sites within the same Sitecore instance without specifying a hostname, just on different ports


Sitecore Desktop usability improvements (package)

While playing with core database for some useful stuffies - I came across some improvements that can save little of my time in day-to-day activities. A screenshot below can say better than few paragraphs of text, so here it is:


It works across all the versions of Sitecore, I in fact had opportunity to test that package against 6.6 and 8.0 Update 4.


Enjoyed that and want to get for yourself?

Download the package: Sitecore Desktop Improvements-1.1.zip (47.5KB)

Previous version: Sitecore Desktop Improvements-1.0.zip (30.8KB)


SwitchMasterToWeb.config for Sitecore 8

I have just tested the one on my Sitecore 8.0 Update 4 instance - it works pretty well!

For those who has never met this config before - SwitchMasterToWeb is a configuration patch file, that aims to be placed into App_Config\Include folder on content delivery server (CD) in order to remove references to master database, that should not present there by design.



	
		
			
			
			
			
			
			
			
		
		
			
			
			
				
			
		
		
			
		
		
			
				
			
		
		
			
				
					
						
							
								
							
						
					
				
			
		
		
			
				
					
						
					
				
			
			
				
			
			
				
			
			
				core
				/sitecore/system/tasks/schedules
				true
			
			
				
			
			
				
					
						sitecore_master_index
					
				
			
			
				
			
			
				
			
		
		
			
				
					
						
					
					
						
					
					
					
						
					
					
					
						
					
					
					
						
					
					
					
						
					
					
					
						
					
					
					
						
					
				
			
			
			
				
					
						
					
					
						
					
				
			
		
		
		
			
				
			
		
		
		
			
				
					web
				
			
		
		
		
			
				
					
						
							web
						
					
					
						
							web
						
					
					
						
							web
						
					
				
			
		
		
		
			
				
					
						web
					
				
			
			
				
					
						web
						sitecore_marketing_asset_index_web
					
				
			
			
				
					
						web
					
				
			
			
				
					
						web
					
				
			
		

		
		
			web
		
	

Wildcard items ("*"-pages) with MVC, passing the correct datasources based on requested item URL

As you probably know, there is a feature in Sitecore, called "wildcard items". Let's say you have a folder where multiple subitems suppose to be and should be presented by similar pages. Sitecore allows you create a wildcard item named "*" (asterisk) so that it will serve any request to this folder. Let's take a look on example below:


Here we see clear separation of pages and data. Airports page has the only child - wildcard page item that is highlighted (and you see its details). Below, in /Data folder, there is a corresponding data sources for each of the airport.

In usual scenario, there should be a page item created for each of airports from /data folder, and page's presentation details screen should have that data items set as the datasource for corresponding rendering (yes, we are on MVC here). But how to have this working, if we have only one universal page item? We have a rendering called Airport to display airport info, but how should we specify the datasource to it?


The rendering relies on RenderingContext.Current.Rendering.DataSource as usual. And instead of datasource of specific airport, we get "*" item as the datasource in all cases, regardless of what airport's page we're loading.

I wanted to leave page's datasource and rendering untouched, as normal implementation. Instead, I decided to incline into mvc.getRenderer pipeline and resolve datasources for "*"-wildcard-items dynamically, based on the URL requested, so that rendering get corresponding data item from RenderingContext.Current.Rendering.DataSource. And of course, as "*"-items serves all possible requests to its folder, I must provide datasources only for matching data items, redirecting all the rest to 404 error page (since there's no data for the page - there's no sense in such a page).

So here's my implementation of wildcard datasource resolver:







Airport
        
      
    
  

Code referenced from configuration patch file:

    public class WildcardDatasource : GetRendererProcessor
    {
        public string RenderingName { get; set; }

        public override void Process(GetRendererArgs args)
        {
            if (args.PageContext.Item.Name == "*" && args.Rendering.RenderingItem.Name.IsSameAs(RenderingName))
            {
                string datasourceFolder = args.Rendering.DataSource.IsOK()
                    ? args.Rendering.DataSource
                    : string.Format("{0}/{1}", Paths.DataFolder.TrimEnd('/'), args.PageContext.Item.Parent.Name);

                string dataSourcePath = string.Format("{0}/{1}", datasourceFolder, 
                    args.PageContext.RequestContext.HttpContext.Request.Url.Segments.Last());

                var dataSourceItem = Sitecore.Context.Database.GetItem(dataSourcePath);
                if (dataSourceItem != null)
                {
                    args.Rendering.DataSource = dataSourcePath;
                }
                else
                {
                    // process 404 page not found
                }
            }
        }
    }


Things to improve in future:

  1. Add support for nested wildcards
  2. Find the way wildcard items work with Page Editor

Afterthoughts about Sitecore official training and certification course

I have just taken official Sitecore Developer Training and Certification in their office in London, near Tower Bridge.

In general, I did not expect the course to be so intensive. 4 days going through all aspects of working with Sitecore filled many gaps in my knowledge of platform. There were 5 of us so everyone could receive proper support and explanation while stuck with anything while studying.

Thanks to our tutor, Raul, who has heroically stood out a flurry of questions from me and gave really great insights on quite advanced topic outside of course agenda.

My advice for those who are just about to sign up for it - treat this course not as a final result by itself, but as a starting point for your individual further investigation. You will not become an expert after getting a certification, but you will be aware of most Sitecore features you need to know at that moment and how they function. Thus, do the notes, as much notes as you can. And ask as much question as you feel important to satisfy your understanding of each exact feature.

Another point I would suggest is to postpone your training if you are complete newbie in Sitecore. In that case, there is a risk you may miss something very important, especially if that becomes a prerequisite for further module. Do your own research before attending the course as much as possible - read multiple blogs, Q&A on StackOverflow etc. and ideally form the list of your own questions that you'd find answers for, while taking the course.

I personally found that very useful, so do recommend to you guys. And yes, if you are successful enough, you shortly receive a certificate like the one below but with your name, and also gain access to Sitecore developers' resources such as SDN forums and support.


So, good luck!

Sitecore.Kernel and Sitecore.MVC delivered via a NuGet library

Update (01 Aug 2015):  Here is the alternative approach answer and the solution for blog post:


I was always wondering, why Sitecore yet hasn't hosted Sitecore.Kernel and Sitecore.MVC on the NuGet?

This would have simplified our (developers') life in some way, as for today, we have to keep an additional /Libs folder and reference those 2 DLLs out of it (but couple others will serve good as well, for instance Lucene DLLs etc.). That could also simplify versioning and dependencies issues for us as soon as we still are using NuGet package management, so we now have 2 folders for references, highlighted below:


If they avoid doing that for licensing purposes - that seems quite strange as mentioned libraries are very little part of what Sitecore is, plus they may just supply obfuscated DLLs via NuGet and normal reflection-friendly via standard platform installation.

Here is what I have in my Libs folder and that I use and reference in small proof-of-concept project:


Dear Sitecore, if you read me, please consider using NuGET - today's industry standard for packaging and resolving dependencies .