Month: October 2011

Create page base classes for Ektron templates

A quick time saver tip today… On my projects I like to create base classes from which items such as ASPX templates and ASCX user controls can inherit.  Base classes are Class Files that are placed into the App_Code folder.  This allows me to place commonly used code into one place that is then made available to all the templates and/or controls in the project.

For example, I have a C# class called “BasePage” which has a public property of “ContentId”.  This property holds the Ektron Content ID for the current paqe.  The Init event of the BasePage class will look for “id” or “ekfrm” or “pageid” on the querystring and use the value to populate the ContentId property.  This means that every ASPX template or ASCX control has a property called “ContentId” from which you can quickly get the content id.

Prior to this I found I was always writing code to get the content Id from the querystring (typically an Ektron template takes in a single content Id).

With these classes in place you will soon, over time, continue to add to them and ultimately this will save a little bit of time here and there.

Test website performance with loads.in

A great free tool that I like to use to test the performance of my websites is loads.in.  This tool will tell you how fast it takes to load your website from different locations around the world.  As you are nearing the end of your development lifecycle you will be keen to ensure that your caching strategy and the page load size of your site is within expected levels.

Loads.in will also provide you with a view of all the elements that make up your pages by going into the waterfall chart mode.  This is useful for seeing how large individual elements are (such as images or CSS files) and also for highlighting any missing files (by spotting 404 errors).

Restricted folder names in Ektron

This one has caught out people a few times.  There are certain values which cannot be used as folder names within Ektron CMS.  They are in effect, protected names which are used by the CMS.  The problem is that it is still possible to use these values (i.e. there is no validation to stop you).

A list of the names I am aware of are here :

  • assets
  • privateAssets
  • workarea
  • uploadedfiles
  • uploadedimages

You will notice that each of these corresponds to a physical folder path in the root of a typical Ektron website.  This is where the problem comes in.  There are lots of code files (both .Net and Javascript) which reference relative folder paths using these values.  So, if you do happen to use these folder names you may get unexpected behaviour in the workarea and on your templates.

The one that usually catches people out is “assets” as this is a good name to give to a folder full of images or PDFs.  Now that you know this, please avoid using them!

If you have already done this, there is a work around here

Quickly translate menus in Ektron

When translating your website into other languages you may find that it is fairly time consuming process!  There are a number of things you can do to speed it up.  This tip will concentrate on translating your menus into other languages.

With the workarea open, go to the Content section and click on Menus.  Select the “Menus” root node in the tree view.  On the toolbar you will see an option that says “Export for Translation”.  If you click this icon the CMS will take you to a screen where you can choose to export the menu to a number of languages.  You will only see a language option if that language has been enabled in the workarea.

You can now go ahead and re-import the menu straight away or have the resulting XLIFF file sent to a translation house.  To import an XLIFF file back into the CMS, go to Settings > Import XLIFF Files.

Once the import is complete you can edit the menus to set the multi-lingual content.

Add item to the library using Ektron API

The Ektron library is a useful area within the CMS that can be used to store all kinds of static files. By static I mean that it is just a basic file to which you will not need to apply metadata, taxonomy, aliases or any of the other features of a CMS asset.

The chances are, at some point you will need to add a file to the Library using the API. Perhaps you are providing a custom method to upload photographs to the CMS or users need to submit their CV as a Word document.

Adding a file to the Library is a two step process. Assuming you have the file already uploaded the file to the web server hard disk (to a temporary location), you first need to copy the file to the right place and then call the API to tell Ektron CMS where the file is. The API call alone will not put the file in the right physical location.

Here is the call to put the file into the right place:


string libraryFilePath = "/uploadedimages" + folderPath + "/" + title + "." + cd.AssetData.FileExtension;


File.Move(Server.MapPath(newImagePath), HttpContext.Current.Request.PhysicalApplicationPath.TrimEnd('\\') + libraryFilePath);

This will move the file from a temporary location into the permanent location within the “uploadedimages” folder. The “folderpath” variable will contain the folder structure where the file is added.
Ektron.Cms.LibraryData libData = new Ektron.Cms.LibraryData();

libData.FileName = libraryFilePath;
libData.LanguageId = languageId;
libData.Title = cd.Title;
libData.ParentId = cd.FolderId;
libData.FolderName = cd.FolderName;
libData.ContentType = 7;
libData.Type = "images";

long libID = 0;
libID = libAPI.AddLibraryItem(ref libData);

The above code is used to add an image to the Library.

Security: Change default passwords in Ektron

When an Ektron site is installed for the first time it includes default users with default passwords set.  A very important security aspect of the CMS is to change these passwords before you go live.  It might sound obvious but you would be surprised how many sites there are with the default passwords still in place!

The following users are available in a default Ektron installation :

  • Builtin
  • Admin
  • jedit
  • jmember

The default password values are the same as the usernames, i.e. builtin is “builtin”, admin is “admin”.

The builtin user is often neglected due to the fact that it is found in a different place to the other users.  For reference, you can find the builtin user in the Settings > Configuration > Setup page (same page as where the license key lives).

Change those passwords!

Improve Ektron compilation performance

The vast majority of projects I build using Ektron are built using the WebSite model (as opposed to the Web Application model). During development I will obviously make lots and lots of changes to code which in turn will cause a lot of compilation to take place.

A quick tweak to the web.config file can improve the performance of compilation by making it more selective.  If you update your web.config file like so:

<compilation … batch=”false”> …</compilation>

This will instruct .Net to only compile the code that it needs to and can speed up the time you wait around for the compiler.  If, like me, you have a slow computer you will really appreciate this!

Another added benefit of this is that it will stop a certain type of .Net error from occurring that you have probably seen at some point.  That error looks something like:

ASP.net Error: The type "xxx.dll" exists in both AAA and BBB

This error tells you that a class exists twice in the temporary .net files folder:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files

By adding batch=”false” this error will go away.

So thats two Ektron tips in one!

Edit : I should point out that this setting should be used in development environments only.

Format code StyleCop

When working with multiple developers on a project it is vital to maintain good coding standards. An important aspect of coding standards involves commenting. Good comments give more meaning to the code in a website and help speed up the ability of developers to fix bugs and/or make improvements. Ektron projects are no different in this respect.

A tool that I use (and is pretty much hated by my team!) is Microsoft’s StyleCop. It is a Visual Studio plugin that you use to format your C# code (I only use C# these days). The reason why I say my team hate it is because, to be honest, some of the rules do seem a little unnecessary and over the top.

I forgive StyleCop these shortcomings because if you keep using it you will reap the benefits of code that always looks consistent. I wish all the projects I have inherited were formatted with StyleCop.

Download StyleCop from here.

Creating new Pagebuilder widgets in Ektron

Ektron’s PageBuilder functionality allows semi-technical users to build web pages in a graphical way using widgets that can be dragged and dropped onto the page. A widget is a small component that performs a specific function such as showing a video or displaying a block of text.

Most Ektron projects tend to make use of PageBuilder and Widgets as they provide a lot of power and flexibility for content authors. If you are new to creating widgets a good starting point is to use one of Ektron’s widgets that are provided with the CMS.

For a “blank canvas”, use the HelloWorld widget. It is very basic but contains the essential widget code that you need for every widget. Simply copy and paste the widget within Visual Studio, then rename the file and the class name and off you go.

Another common widget to copy is the ContentBlock widget. Quite often I need to show a “special” type of ContentBlock that needs to look or behave in a specific way. For example, maybe you are showing a video with a custom video player. The ContentBlock widget could be customised to default to the video folder or to only show video content in the browser. These are relatively small changes to make that can make the content editing process much easier for end users.

A third example would be to take the default Collection widget and re-purpose it to work as an ImageGallery (for instances where you might need to use a specific ImageGallery as requested by the client).

Make all aliases lower case

Aliasing helps Ektron websites to provide friendly URLs that are readable and search engine friendly. Automatic aliasing is a time saving device that creates the friendly URLs based on either taxonomy or folder structure.

A common issue is that aliases usually need to be all in lower case whereas taxonomy and folder names will have mixed case. This can cause problems with SEO because search engines will interpret the mixed case and lower case URL as being different pages even though they link to the same page.

A good way to resolve this is to use the Microsoft URL Rewrite plugin for IIS7. Once this is installed a new option becomes available within the IIS Manager called “URL Rewrite”. The rewriting can be applied to the whole site – one important exception to this is to exclude the workarea.

Once URL rewrite is installed, go to IIS Manager, click on your site’s root node and then double click on the URL Rewrite icon in the IIS section. Next click “Add Rule” and a dialogue window will open. Select the “Enforce lowercase URLs” option in the SEO section and click OK.

Now go to the workarea folder in IIS, open URL rewrite and remove the rule. Otherwise you will get strange behaviour from the menus in the workarea.