Detecting Page or Post on render

Oct 2, 2008 at 11:40 PM
Hi all!

I'm looking to detect if the site is rendering a page or a post from the site.master.  I don't see any clear way to do this, and thus far I have been parsing URL's to detect the presence of  "\default.aspx" in the URL to know if I'm on the homepage.  I've found the IsFrontPage, now I'm looking to know if we are rendering a page item or post item.

Anyone know how this might be done?  Thanks in advance!

Oct 7, 2008 at 8:11 PM
I'm still looking in case anyone knows how to answer this one...
Oct 8, 2008 at 9:30 PM
You could attach to the static BlogEngine.Core.Page.Serving Event in the site.master during the OnInit function.

This would notify you during the page's onload event, that the master is serving up a page instead of a post.
Oct 8, 2008 at 10:01 PM
Edited Oct 8, 2008 at 10:02 PM
Thanks mmcdanie, that makes sense.  I'll try that and see what I can do with it.  I assume that one of the parameters within the OnInit will contain the info I need, or is just the fact that the event fired means it's a page and not a post?

Testing will probably answer that question for me...

Oct 8, 2008 at 10:25 PM
When you bind to the event, the sender parameter of the function will be the page object.  Although, the ServingEventArgs parameter will also have the page location marked as ServingLocation.SinglePage as opposed to SinglePost/PostList/etc.