4

I am having issues when trying to get the PageMeta from the page directly. Below is my sample code. Can you please advice me if I am doing it wrong?

Error Message: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index at IPageMeta pageMeta = (IPageMeta)result[0];

/*
Use PageMetaFactory and retrieve the metadata of the page located at
/us/potential-at-work/application-leaders/article.aspx
*/
string pubID = "tcm:0-12-1";
string url = HttpContext.Current.Request.Url.AbsoluteUri;

PageMetaFactory pageMetaFactory = new PageMetaFactory(pubID);      

IList result = pageMetaFactory.GetMetaByUrl(url);
IPageMeta pageMeta = (IPageMeta)result[0];

1 Answer 1

7

As you state in your code comment, you need to pass in only the path of the URL (i.e. /us/potential-at-work/application-leaders/article.aspx). The problem is that you are using AbsoluteUri, which returns the entire URL as per http://msdn.microsoft.com/en-us/library/system.uri.absoluteuri(v=vs.110).aspx. As such pageMetaFactory.GetMetaByUrl(url) returns an empty collection and you try reading the first element. Hence, the index our of range.

You should be using AbsolutePath as per http://msdn.microsoft.com/en-us/library/system.uri.absolutepath(v=vs.110).aspx.

I suggest also you check what is the actual URL of the page, either by looking it up in the Content Delivery DB, table PAGE, column URL, or on the Content Manager side, object Tridion.ContentManager.CommunicationManagement.Page, property PublishLocationUrl.

2
  • Thank u Mihai. It is working now.
    – Vandana
    Nov 27, 2013 at 21:37
  • Once I get the Page meta (metadata filled being Category and Keyword field), is it possible to get the TCM URI of the Keyword and then get the metadata filled values of the Keyword? String editionVal = compCustomMeta.GetValue("edition");
    – Vandana
    Dec 5, 2013 at 18:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.