Friday, November 17, 2017

Sitecore 9 QuickStarts - Getting Started With xConnect

The best place to get started with XConnect is using Martina's documentation. It walks you through your basic XConnect console application.

Once you have this console app building start taking a look at the Jason Wilkerson blog articles on XConnect. Although tempting, do NOT start with Jason's articles. It is important that you get Martina's application working first and then start adding functionality from Jason's articles. The reason is that Martina's will do all the client certificate stuff properly and that is what you want for production.

I started myself with this console app and am now using Jason's blog articles myself.  My hope is to build out a repository on GitHub along with a series of articles on how to integrate XConnect with a variety of other applications in hopes this will save others time doing this.  If you are building an integration maybe we can collaborate and then add it to the repository for others to use.

When you create your project in Visual Studio 2017, if it defaults to creating your console app as 4.6.1 and you switch to 4.6.2 you may get an error about the root node.  If you do it is a bug in the conversion.  Check your app.config file and make sure it is formatted like this.  In my case it removed the configuration node and put startup within appSettings.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
  </startup>
  <appSettings>
    <add key="xConnectCertificateThumbprint" value="082FF77F7C87A93A3C5FE88CFB3DAB730DEF331A"/>
  </appSettings>
</configuration>

If you do not see the 4.6.2 option in Visual Studio 2017 then you need to install the developer pack

Troubleshooting

The error you may run into and in fact I did is, "Sitecore.XConnect.XdbCollectionUnavailableException: 'The HTTP response was not successful: Unauthorized' The StackExchange mentions these 3 causes:

  1. Your thumbprint or certificate is not properly installed so you are being blocked from connecting to xConnect
  2. Your application does not have access to the certificate (e.g. IIS user does not have permission)
  3. You did not execute the script in the installation guide Post-installation steps.
On first install I had forgot to run the execution script, doh. The second time around it was the second one but it was a step further it was not the certificate itself but a policy applied to my laptop by IT that was not allowing the root authority because I was generating a self-signed certificate on my development environment. Hopefully this will help you when you run into this issue.

If you are running into issues with 401 or 403 errors connecting to xConnnect then this article can help you troubleshooting the certificate issues. It is all about xConnect Security


Monday, November 13, 2017

The Glass is Half Empty - Why can I not get all children of type Image from the media library folder?

So here is the problem.  I have a component where the user assigns a media folder for say a photo gallery.  Now I simply want to pull in all images from beneath this folder. I was tempted to do this but it always returns null.

imageFolderItem.Children.OfType<Image>()

But why?  Well according to Sitecore Poutine (Corey Smith AKA Sitecorey) the Image represents an Image field not the Sitecore Image template.  So to accomplish this you would simply do the following:

Go to the definition of Image and copy the class.  Make your own class but call it ImageItem.
Now set the TemplateId to be the Id of the Image template in Sitecore.

    /// <summary>
    /// This is an item based on the image template. If you are after the field use Image.
    /// </summary>
    [SitecoreType(TemplateId = "{F1828A2C-7E5D-4BBD-98CA-320474871548}", AutoMap = true)]
    public class ImageItem : IgnitionViewModel
    {
        //
        // Summary:
        //     Gets or sets the alt.
        public string Alt { get; set; }
        //
        // Summary:
        //     Gets or sets the border.
        public string Border { get; set; }
        //
        // Summary:
        //     Gets or sets the class.
        public string Class { get; set; }
        //
        // Summary:
        //     Gets or sets the height.
        public int Height { get; set; }
        //
        // Summary:
        //     Gets or sets the H space.
        public int HSpace { get; set; }
        //
        // Summary:
        //     Gets the SRC.
        public string Src { get; set; }
        //
        // Summary:
        //     Gets or sets the V space.
        public int VSpace { get; set; }
        //
        // Summary:
        //     Gets or sets the width.
        public int Width { get; set; }
        //
        // Summary:
        //     Gets or sets the media id.
        public Guid MediaId { get; set; }
        //
        // Summary:
        //     Gets or sets the title.
        public string Title { get; set; }
        public Language Language { get; set; }
    }

Now your call can look like this:

     imageFolderItem.Children.OfType<ImageItem>());

And my Symposium 2017 Selfie pictures are returning.













I wish I had found this article a couple hours ago so if you have written one on this issue and have a better description on what the issue is and how to solve it comment here.  Hopefully this will help someone else with the issue.

Wednesday, November 8, 2017

Sitecore 9 QuickStarts: Installing Sitecore 9 In Development Environment

Installing Sitecore 9

Now that you are back from Sitecore Symposium and the announcement has been made you are likely wanting to get started installing it.  This article will help you get it set up and offer tips on places where you could run into issues.

WARNING: The focus of this blog on the local developer environment install and getting you started. If you are installing in any other environment you will want to follow a different set of instructions. If you need help with that let me know I would be glad to help personally or direct you to someone whom can help.

Just like my you are probably lazy and will want to follow the Lazy Way to Install Sitecore 9 and that is right. However before following the lazy way you need to download the right version. As of this article it is the Sitecore 9 Initial Release.


Once you have the Sitecore 9 downloaded, you will want to use Jeremy's Gist script.  This article explains how the Low Effort SOLR Install script works.

SPECIAL NOTE FOR Windows 8 or 10: If you have not already you will need to enable the Local Admin account. After you have done this you can create a local admin account for SOLR to run under as well as set up app pool users.

If you are new to SOLR, please be aware that SOLR is a Java technology so you will required to Install Java to run it. If after install SOLR will not start then you probably have to install Java. You can confirm this by opening a command prompt (Run as Administrator and then CD SOLR\solr-6.6.2\bin changing the version if you have a newer version of SOLR.  Then type solr start. You will get the error saying:

error: java.exe not found

If java is installed and still get the error check the path in your environment variables JAVA_HOME. Mine was set to the wrong path, an older version of Java.

You can confirm SOLR is running by going to the admin https://solr:8983/solr if you changed your port then this may be different but if you stuck with the defaults it should show the SOLR admin

Save yourself some time and get the pre-requisites installed:


  • Install Microsoft Web Platform Installer
  • Search for "Web Deploy 3.6 For Hosting Servers" make sure it is this version because if it does not say For Hosting Servers it will bite you later.
  • Install SIF. To do so open Windows Powershell ISE (Run as Administrator)
  • In console at the bottom run Register-PSRepository -Name SitecoreGallery -SourceLocation https://sitecore.myget.org/F/sc-powershell/api/v2
  • Then run Install-Module SitecoreInstallFramework 
  • Then ensure you have the latest by running Update-Module SitecoreInstallFramework


Once you have SOLR installed and the pre-requisites then follow the Lazy Way to Install Sitecore 9 I used the Rock Paper Scissors UI mentioned in the article as it will generate the scripts and run them if you would like.

When I installed the first time, I unchecked the checkbox so it would run automatically but then ran into issues with permissions writing to the host file. A better approach is to set the permissions on the host file then open Windows Powershell SPE (Run as Administrator) then in the command window enter this command:

Set-ExecutionPolicy RemoteSigned

After that then run the generated script.  This worked well for me. I have now copied Jeremy Davis' script along with Kam's to my R2D2 Unit for transport to any dev machine that needs it in the future.



Possible Issues and Troubleshooting

First Time Install

I mentioned a couple things inline in the install section but there are a few other things that may help you will resolving issues.

ISSUE: Error requesting 
http://xp0.sc/sitecore/admin/PopulateManagedSchema.aspx?indexes=all: The remote server returned an error: (500) 
POSSIBLE RESOLUTION: Check event log and in my case it said "Login failed for user 'collectionuser'. Reason: Could not find a login matching the name provided. [CLIENT: <local machine>]"  Now in my case I had to add that user to my database and ensure it had access to the proper permissions. If you are using another user for the collection user then you need to edit the connectionstring.config however note that there are now 2 connectionstring.config files.  The first in in App_Config but the other is in \App_data\jobs\continuous\IndexWorker\App_config\ConnectionStrings.config make sure you change both.

ISSUE: Error hitting xconnect in browser:
Handler "ExtensionlessUrlHandler-Integrated-4.0" has a bad module "ManagedPipelineHandler" in its module list
Now there is the normal spot in "Turn Windows Features On" for .NET 4.7 however there is also the other spot that is not as obvious place under "Turn Windows Features On" under "Internet Information Services > World Wide Web Services > Application Development Features" Navigate there and check ASP.NET 4.6

Re-Running The Install


Now if you ran the install and it failed, upon running it a second time you may run into other issues.
The first error you will get is:

 You must remove all users with password before setting the containment property to NONE.

The issue that the users cannot be deleted by the SIF process. the fix then open SQL Management Studio and delete the SQL Server user from the databases that were created. This stack exchange post describes it in detail.

If you need help installing Sitecore 9 let us know and we will be glad to help out. I myself have only installed it in a local dev environment at this point but I am sure I will be doing it in a cloud capacity before you know it as well.

If you are looking for a mentor to connect with you on a regular basis for Sitecore or any other technology, Read Watch Create can arrange an introduction. Email me at chris.williams@readwatchcreate.com and I can arrange for mentoring sessions at a reasonable rates.