<?xml version="1.0" encoding="utf-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><language>en</language><title>Blog posts by Tomas Unestad</title> <link>https://world.optimizely.com/blogs/Tomas-Unestad/</link><description></description><ttl>60</ttl><generator>Optimizely World</generator><item> <title>How to get PageTypeBuilder to work with EPiServer Composer</title>            <link>http://labs.dropit.se/blogs/post.aspx?id=fbee31d3-1c71-4a36-a8c1-4a5297eb66ab</link>            <description>&lt;p&gt;Today when setting up a new project I ran in to some issues with PageTypeBuilder and Composer.&lt;/p&gt;
&lt;p&gt;The problem was when Composer was about to register it&#39;s Content Areas it loads the PageTemplate without an pageid. This natrually makes EPiServer assume that you are requesting the startpage. PageTypeBuilder will then try casting the CurrentPage-PageData which is of the type StartPage to a TypedPageData of the type which the .aspx-file inherites from.&lt;/p&gt;
&lt;p&gt;But the current page will be of the type start page. To fix this problem, we had to change the PageTypeBuilder.UI.TemplatePage to acknowledge composers odd way of registering it&#39;s content areas. We had to change the CurrentPage property to this.&lt;/p&gt;
&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;public new T CurrentPage
        {
            get 
			{
				
				if (!string.IsNullOrEmpty(System.Web.HttpContext.Current.Request.QueryString[&quot;DE_VM&quot;]) &amp;amp;&amp;amp; System.Web.HttpContext.Current.Request.QueryString[&quot;DE_VM&quot;] == &quot;2&quot;)
				{
					int? id = PageTypeResolver.Instance.GetPageTypeID(typeof(T));
					return (T)DataFactory.Instance.GetDefaultPageData(PageReference.StartPage, id.Value);
				}

				return (T)base.CurrentPage; 
			}
        }&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The other thing we hade to change was in PageTypeBuilder.UI.LoadTypedCurrentPage. In the CurrentPage property it gets the PageData from the current PageLink, which in our case will be the link to the start page, and verifies that it inhertis the correct type. This will cause PageTypeBuilder to throw an exception saying &quot;The current page is not of type MyPageType.&quot;. In the case of Composer regestering it&#39;s content areas we really doesn&#39;t need the right PageData so we can just return the PageData before it verifies if it is inheriting the correct type. This was done by modifing the CurrentPage property to this.&lt;/p&gt;
&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;public virtual PageData CurrentPage
        {
            get
            {
                if (_pageData == null &amp;amp;&amp;amp; PageReference.IsValue(Page.CurrentPageLink))
                {
                    _pageData = Page.GetPage(Page.CurrentPageLink);

					if (!string.IsNullOrEmpty(System.Web.HttpContext.Current.Request.QueryString[&quot;DE_VM&quot;]) &amp;amp;&amp;amp; System.Web.HttpContext.Current.Request.QueryString[&quot;DE_VM&quot;] == &quot;2&quot;)
					{
						return _pageData;
					}
                    if (!_pageData.InheritsFromType())
                        throw new ApplicationException(
                            string.Format(&quot;The current page is not of type {0}.&quot;, typeof(T).Name));

                }
                return _pageData;
            }
            set
            {
                if (value != null &amp;amp;&amp;amp; !value.InheritsFromType())
                    throw new ApplicationException(
                        string.Format(&quot;The current page is not of type {0}.&quot;, typeof(T).Name));

                _pageData = value;
            }
        }&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://labs.dropit.se/blogs/file.axd?file=2009%2f10%2fPageTypeBuilder.zip&quot;&gt;PageTypeBuilder.zip (18.71 kb)&lt;/a&gt;&lt;/p&gt;</description>            <guid>http://labs.dropit.se/blogs/post.aspx?id=fbee31d3-1c71-4a36-a8c1-4a5297eb66ab</guid>            <pubDate>Thu, 22 Oct 2009 14:56:00 GMT</pubDate>           <category>Blog post</category></item></channel>
</rss>