Tag : configuration

ShowConfig on Content Delivery

The Problem

Today I was troubleshooting a problem on a content delivery server. I knew the problem was around configs, but I needed to see the combined config to determine what the exact problem was. Normally, I would login to Sitecore and go to /sitecore/admin/showconfig.aspx and I would see a beautiful XML file that shows me the merged config.

The problem? The Sitecore back-end is removed on content delivery servers! There’s nowhere for me to login, and there’s now ShowConfig.aspx.

What to do?


I remembered back to a Kam post in which he demonstrated how to login to Sitecore without credentials, as long as you had file system access. I have file system access to the CD right now… can I create my own ShowConfig?


Using dotPeek, I reflected into Sitecore.Client.dll and was able to see that all the ShowConfig.aspx file is is a call to CheckSecurity(), followed by Factory.GetConfiguration() which is dumped into the response. Simple enough, no?


I created an XML file in the Website directory on the CD called ShowConfig.aspx and copy/pasted the code from the real showconfig into it. I had to change around the formatting a bit in order to convert a .cs file into an .aspx file.

Here is the result:

<%@ Page Language="C#" AutoEventWireup="true">
<%@ Import Namespace="Sitecore.Configuration">
<%@ Import Namespace="System">
<%@ Import Namespace="System.Xml">

 XmlDocument configuration = Factory.GetConfiguration(); 
 Response.ContentType = "application/xml"; 

It’s as simple as that! I can now navigate to /showconfig.aspx and see the merged config on the CD instance.

Don’t forget to remove this file when you’re done!

Creating Custom Server Roles in Sitecore 9

Sitecore 9 brings about a new feature: Server Roles. This is actually one of the features I was most excited about.

What is a Server Role?

Sitecore 9 ships with 5 server roles: ContentManagement, ContentDelivery, Processing, Reporting, Standalone. You can read more about what each role is used for from their documentation page. Using these server roles, you can conditionally load sections of configuration based off the server role. Rob Ahnemann wrote a more in-depth blog post that you should check out if you want more information on what you can do with server roles.

What Role is Right for Me?

Standalone is typically used for local development. Emphasis on the word “typically.” Many dev servers are typically Standalone environments too. I may have a configuration that I want to be set on local environments, but not the dev server. What role would I use?

None of them!

You’re not limited to using just the 5 roles. You can also set more than one role at a time. If you take a peek at web.config:

<!-- SUPPORTED SERVER ROLES Specify the roles that you want this server to perform. A server can perform one or more roles. Enter the roles in a comma separated list. The supported roles are: ContentDelivery ContentManagement Processing Reporting Standalone Default value: Standalone -->
    <add key="role:define" value="Standalone" />

you’ll see that the role value is currently “Standalone”. This is actually a comma-delimited list of roles.

Proof of Concept Time

I tossed a random config file into the App_Config/Include folder:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/">
        <foo role:require="LocalDev">foobar</foo>

Notice I wrote “LocalDev” as the required role? I went to /sitecore/admin/showconfig.aspx and did a CTRL+F for “foobar”. 0 Results! What happens if I change the defined roles now?

<add key="role:define" value="Standalone,LocalDev" />

Save. Refresh. Search.
We have a winner!

<foo patch:source="dev.config">foobar</foo>

is now present in the ShowConfig.aspx

Hope this helps anybody looking to work some config magic on their solutions.

Still want to learn more? Check Kamruz Jaman’s blog post showing more advanced features and tricks for server roles.