Check for Front Page in Master Page

Jun 10, 2008 at 10:19 PM
In the code behind of the Master Page, is there anyway to check if the page being loaded is the front page of the site?
Jun 10, 2008 at 11:30 PM
I suggest not to edit the code behind in the master page for this purpose. Master page belongs to specific theme. If you edit a master page, when you change theme, your change will not be availabe in the new theme, unless you also edit the master page of the new theme.

If you intend to check whether current page is the front page, you can do it in Page.aspx. As you might already knew, the UrlRewrite module will rewrite the request path to Page.aspx if the front page is a specific page. Inside the Page.aspx code behind, you can also refer to this.MasterPage property and manipulate it.

Regards,
Agus Suhanto
Aug 29, 2008 at 9:38 PM
In site.master.cs

 

private bool m_pageMode = false;
public bool pageMode
{
get { return m_pageMode; }
set { m_pageMode = value; }
}

 

 

string szRoot = Utils.RelativeWebRoot + "default.aspx?";
if ((Request.RawUrl.ToLowerInvariant().Equals(szRoot)) || (Request.RawUrl.ToLowerInvariant().Equals(Utils.RelativeWebRoot)))
{
BlogEngine.Core.
Page front = BlogEngine.Core.Page.GetFrontPage();
if (front != null)
{
pageMode =
true;
}
}

Then in site.master..aspx

 

<%

if (!pageMode) { %>

If you want something different on all pages instead of posts, you also need something like 

 

if

((Request.RawUrl.ToLowerInvariant().Contains("/page/")) ||  (!string.IsNullOrEmpty(Request.QueryString["page"])))
{
pageMode = true;
}