Sitecore Azure Install Management Certificate Bug

This post, “Sitecore Azure install management certificate bug” contains information and resolution about an installation error received while creating a new environment via Sitecore Azure module. The issue is related to generation of “.publishsettings” file.

One of my colleague Shivam Barve faced this issue while he was trying to have his hands on Sitecore Azure installation. Trying to generate .publishsettings via “Install management certificate”, he was not able to download the file from Install Management certificate dialog.

Sitecore-Azure-PublishSettings

After having his head around with “This page can’t be displayed” error.

Certificate error

I was called in for a helping help. Looking at the error I discovered that the url that is being referred for generation of .publishsetting file was incorrect. It was still using older “https://windows.azure.com” url, but Microsoft has already updated the Azure management portal to “https://manage.windowsazure.com/”. So earlier, for generation of .publishsetting file the url was like “https://windows.azure.com/download/publishprofile.aspx” after new Azure portal it is now https://manage.windowsazure.com/publishsettings/.

I was aware of few knowledge base post for sitecore azure hence visited “Error when installing management certificate for Sitecore Azure” article which explains about two options for generating the .publishsetting file.

Option A did help us generating the .publishsettings file but when we tried uploading it in Sitecore azure we were having “Failed to find certificate in publishsetting file” error.

Sitecore-Azure-Error4

Now the last card that can rescue us was sitecore support, reply from sitecore support (specifically Yuriy Yurkovsky, thanks to him for providing the solution) agreed that it is a bug for the current module version. Microsoft uses a new PublishSettings schema version in new management portal, and this version is incompatible with current module of sitecore azure. For generating .publishsettings file based on old schemaversion we were asked to use the following url.

https://manage.windowsazure.com/PublishSettings/index?client=&schemaVersion=1.0

Bingo!! That did helped us for generating the correct .publishsettings file.

Further googling about the schema version change and comparing the old and new .publishsettings file I discovered the following change.

publishsettings schema2.0

As highlighted in above image the new publishsetting file has an attribute  SchemaVersion=”2.0″. So if your file contains this attribute it will not work with sitecore azure module. The old publishsetting file looks like,

publishsetting schema

Sitecore support now has reported this as a bug and will notify once the bug is resolved. Oh! Are you worried how will you be notified for the issue resolution? I will update this post once the update is released for Sitecore Azure module. Alternatively you can also keep watch on Sitecore Azure Module page at SDN. Till then keep watching this space and keep sharing sitecore knowledge!

Sitecore has now come up with an alternate solution for fixing this issue check the knowledge base article, “Error installing a management certificate in Sitecore Azure when using the 2.0 format of the publish settings file

CustomItemGenerator – Raw Vs Text value

Sitecore community is growing and there are so many market place modules, I came across one such gem from the market place “Custom Item Generator” will refer as CIG in the rest of the post, CIG creators also refer it as “CIG”. In this post I am not going to describe introduction of Custom Item Generator, how CIG can be configured? etc etc… All basic information related to CIG can be found at,

–          Marketplace CIG

–          Custom Item Generator

–          Custom Item Generator: A Simple Example

–          Custom Item Generator: Customization

Why I am writing this post?

Purpose of writing this post is to compare usage of FieldName.Text and FieldName.Raw properties.

I was facing this particular issue where I was not able to see rendered YouTube video in “Page Editor” mode. I was creating a sublayout that should render a YouTube Video and it should also be edited via page editor. The video was rendered in an iFrame where in the src attribute should point to the video on YouTube.

At first, I thought it would be a page editor issue and it might not render content from iFrame. So tried placing simple html iFrame tag without any dynamic attributes assignments from code behind and it was rendering the video correctly.

The same issue I was facing with items in the dropdown where in the <input> tags were rendered instead of the names of the items.

Custom Item Generator - 1

I debugged my code and with help of quick watch in visual studio found that FieldName.Text and FieldName.Raw both are returning different values. This made me interested as to why FieldName.Text provides html tag and not only the actual value.

Looking further at the documentation of CIG I found below explanation on CIG blog which suggested the usage of the .Text and .Raw properties.

  • FieldName.Text – This will access the field through the Sitecore field renderer, in most cases where you are displaying a field’s content on the front end you would want to use.
  • FieldName.Raw – This will return the underlying value that is being stored in the field.

Digging further and making use for RedGate Reflector I figured out that .Text calls indirectly FieldRenderer.Render.

public string Text
{
    get
    {
        return base.Rendered;
    }
}

Extract from BaseCustomField

public string Rendered
{
    get
    {
        if (this.field == null)
        {
            return string.Empty;
        }
        return FieldRenderer.Render(this.item, this.field.InnerField.Name);
    }
}

So the conclusion is if you want to render a general link field or an image field and would also like to have page editor support use FieldName.Text. If your requirements are content should not be edited via page editor as was in my case for dropdown and iFrame, make use of FieldName.Raw.

If you are interested reading further for the difference between raw and rendered values check this blog post “RAW VS RENDERED FIELD VALUES” written by Martina.

Sitecore Media Item download

Looking for a code that helps you download Media items from sitecore? This post might help you.

Based on a project requirement I was asked to work on a functionality for having a download brochure drop down. A thought might have come to your mind why a drop down for downloading brochures, well my mind too said “what a wired request?”. Why not we just display links for the brochures. But we need to follow the designs and respect client’s requirements. So I created a drop down which displayed items that comes from a multilist field.
Initially I had the media item’s url as the options value for my drop down, but then came across GetMediaStream() method which does the work for getting a media item into a stream so I tweaked my approach and passed item ID in the value for options.

protected void Page_Load(object sender, EventArgs e)
{
  Item currentItem = Sitecore.Context.Item;
  if (currentItem.Fields["MultiListField"] == null) return;

  MultilistField mltFld = currentItem.Fields["MultiListField"];
  foreach (var item in mltFld.GetItems())
  {
                ddlDownloadBrochure.Items.Add(new ListItem(item.Name, item.ID.ToString()));
  }
}
protected void ddlDownloadBrochure_SelectedIndexChanged(object sender, EventArgs e)
{
  if (ddlDownloadBrochure.SelectedValue == null || ddlDownloadBrochure.SelectedValue == "0") return;

  PromptDownloadBrochure(ddlDownloadBrochure.SelectedValue);
}

Below is the method that will fetch all the details of media item, including name, extension and push it back as response.

private void PromptDownloadBrochure(string mediaID)
        {
            ID id = new ID(mediaID);
            if (id.IsNull)
                return;

            MediaItem mediaItem = Sitecore.Context.Database.Items.GetItem(id);
            if (mediaItem != null)
            {
                Stream stream = mediaItem.GetMediaStream();
                long fileSize = stream.Length;
                byte[] buffer = new byte[(int)fileSize];
                stream.Read(buffer, 0, (int)stream.Length);
                stream.Close();
                Response.Clear();
                Response.CacheControl = "public";
                Response.ContentType = "application/octet-stream";

                Response.AddHeader("content-disposition", "attachment; filename=" + mediaItem.Name + "." + mediaItem.Extension);
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                Response.BinaryWrite(buffer);
                Response.End();
            }
        }

You can allow the download on a button click or any other asp.net control which does a post back.