Dominik Juszczyk Technical blog

14Dec/081

LinkItemCollection property in EPiServer

I was really happy reading on EPiServer Labs blog post by Ted Nyberg that in EPiServer CMS 5 R2 there is a new property type introduced - LinkItemCollection. You can read more on Ted's blog - but in short, it is a native property that does what old good Multi-page property has done so far (and some others implementation of multi link property).

I was using multi-page property in many projects and still I will be using it on all EPiServer 4.6x projects, but for sure, in all new CMS 5 I will go with LinkItemCollection. Especially that what I have just checked it is "smarter" then Multi-page property. "Smarter" because it knows what links it stores - and for example, while moving document (or deleting) that is referred by LinkItemCollection now we will get a warning. This was  not possible with Multi-page property.

Still there are some areas where probably I will stick to Multi-page property. It is great base for creating new specialized properties for different purposes.  We have created few new properties for which Multi-page property source code was a base like for example property called multi-image list - which allows for adding images with caption, alt text, link URL and so on. I'm not sure for now if it is possible with the new property - if not multi-page property isn't dead for us (at least for the time being :) )

7Jun/082

How to make a page type a ‘leaf’

In one of my projects I had to create page type that was supposed to be a 'leaf' in page tree structure (for this page type no children should be possible to create). First thought was to go to admin mode, to configuration of page types and turn off all page types on "Available page types". I was very surprised that it can't be done. Even if one chooses no page types to be available and save configuration it does not work (when one will open this tab again - all page types will be chosen).
After short investigation I have found post on EPiServer forum. Greger Olofsson describes there some possibilities how this can be achieved. I have tried two of them:

  • create a dummy page type and choose it not to be available in edit mode and then select it as only one available for our 'leaf' page type,
  • subscribe to the CreatingPage event and check what page type name (or id) is used and abort the creation of the new page

Both of them works but have some drawbacks. When selecting dummy page for our 'leaf' page type in edit mode, after clicking 'Create New' link (from context menu or toolbar) we get this page:


It may be confusing for editors because it gives no information why there is no new page page type to choose.
Subscribing to CreatingPage event is not better. I did it with this code (in Global.asax.cs):

protected void Application_Start(Object sender, EventArgs e)
{
EPiServer.DataFactory.Instance.CreatingPage  = new EPiServer.PageEventHandler(OnCreatingPage);
}

private string[] GetLeafPageTypes()
{
string leafPageTypesConfigurationValue =   System.Web.Configuration.WebConfigurationManager.AppSettings["leafPageTypes"];
string delimStr = ",";
char[] delimiter = delimStr.ToCharArray();

return leafPageTypesConfigurationValue.Split(delimiter);
}

protected void OnCreatingPage(object sender, PageEventArgs e)
{
PageData parentPage = EPiServer.DataFactory.Instance.GetPage(e.Page.ParentLink);
foreach (string leafPageType in GetLeafPageTypes())
{
if (parentPage.PageTypeName.ToLower() == leafPageType.ToLower().Trim())
{
e.CancelAction = true;
e.CancelReason = "Page type is lea";
return;
}
}
}

Few words of explanation. I decided to keep configuration which page type is a leaf in web.config which looks like this:

<appSettings>
<add key="leafPageTypes" value="[Public] Start page,[Public] Search page" />
</appSettings>;

It does work and does not allow new page to be created. It does show my warning to the editor ("Page type is a leaf"). But it is done after choosing page type of new page and after pressing Save button (so also after editor has filled in all properties values and after seeing informations which properties are mandatory to fill).

Then for some time I tried to modify context menu (the one that is showing on right mouse button) but I realized that I will also have to modify toolbar (where new page button is present also). And then I decided to do it in NewPage.aspx file located in edit folder. I know that this shouldn't be done mostly because it will be lost (it can be lost to be more specific) during upgrades. But my change is very simply and very easy to add after possible upgrade. What I did? I have added to this page similar code as I tested on CreatingPage event. I have added to markup file those lines:

<%@  Import namespace="EPiServer"%>
<%@  Import namespace="EPiServer.Core" %>
<script runat="server">
private string[] GetLeafPageTypes()
{
string leafPageTypesConfigurationValue =   System.Web.Configuration.WebConfigurationManager.AppSettings["leafPageTypes"];

string delimStr = ",";
char[] delimiter = delimStr.ToCharArray();
return leafPageTypesConfigurationValue.Split(delimiter);
}

protected override void OnLoad(System.EventArgs e)
{
foreach( string leafPageType in GetLeafPageTypes() )
{
if (CurrentPage.PageTypeName.ToLower() == leafPageType.ToLower().Trim())
{
ErrorMessage.Text = "Page type is leaf. Cannot have children";
PageTypeList.Visible = false;
Cancel.Visible = false;
}
}
base.OnLoad(e);
}
</script>

and Label control to display my message:

<asp:Label ID="ErrorMessage" runat="server" ForeColor="red" ></asp:Label>

I'm still using appSettings key to keep configuration which page type are a 'leaf' ones. Now when editor wants to create new page under 'leaf' page type page after clicking "Create New" link he/she sees that information:

So as you can see I achieved two things:

  • it is possible to define page type (or page types) as a 'leaf' by editing one key in web.config
  • it is easy to make page type a 'leaf' just for some time without changing it's configuration (available page types)
  • editor now can see information why he/she can't create new page with chosen parent.

I suppose that there are different way to do something similar. If you know them - please let me know :)

13May/080

WebResource.axd problem in EPiServer CMS 5

With our first EPiServer CMS 5 based solution we had strange problem related with WebResource.axd. We were getting the exception:

The WebResource.axd handler must be registered in the configuration to process this request

After searching for this exception in Google I have found a post about this on Fredrik Haglund's blog. We have had applied his patch and it seems to solve the problem (at least until it will be solved by EPiServer or whoever responsible for that).
Anyway I thought that we did something special in that one project and that this problem is that project specific only. Unfortunately it occurred that the exception is thrown from time to time in all our EPiServer CMS 5 projects. The worst thing is that we are not able to reproduce error or identify what makes this error more probable to occur. It is thrown from time to time without any clear reason.
For now we have started to adding patch to all ours CMS 5 projects. But this is something that has to be solved somehow. We are monitoring EPiServer's forum and waiting for this problem to be solved. When you will read comments to the Fredrik's post you can see that they are working on that - and I will keep my finger crossed for them to fix it :)

UPDATE:
Today I have found this post. It seems that the reason of error has been found and that there is a workaround.

25Mar/080

Do security updates! (and remember to include that in the requirements of the server specification)

In one of the projects I was technical architect in we were struggling with strange error. When accessing main URL of the application we were getting NullReferenceException. But when accessing same site with language code at the end of URL everything was ok. What was the problem? Lack of SP1 for .Net Framework 2.0 installed.
There is also second lesson. Be very detail when crating specifications. When we were delivering server specification we told the Administrator that we will need .Net Framework 2.0. We forgot to mention that all security updates has to be installed on the server.

Here is the link to the problem and it's solution description.