I am referring to the person.aspx page that lives in the MySite host. I figured this would be a page that has a few web parts on it and little or no code behind. Boy was I wrong! My colleague Amol posted a blog about how to add navigation to your MySite. Amol’s post should be read before implementing any code from this post. Amol’s post came as a result of us trying to figure out how to add the tabs to the MySite host. After implementing Amol’s changes and still not seeing any additional tabs on the MySite Host, I decided to disassemble the code for the page…this is what I found:
protected override void OnPreRender(EventArgs e)
{
if (base.IsProfileError || !base.Profile.IsSelf)
{
Control master = base.Master;
if (master != null)
{
master = master.FindControl("PlaceHolderTopNavBar");
}
if (master != null)
{
master = master.FindControl("PlaceHolderHorizontalNav");
}
if (master != null)
{
master = master.FindControl("TopNavigationMenu");
}
if (master != null)
{
master.Visible = false;
}
}
base.OnPreRender(e);
}
Who would have thought that the navigation would be hidden by the page and not by the provider…not me? So here is what I did to change the page. First I created a new site template. In the 12 hiveSite Templates I copied the SPSMSITEHOST folder and pasted it in the same folder. I then renamed the pasted folder. Next I changed the code behind of the page to the one that I had written. The new code for the page is as follows:
public class NewMySitePublicWebPartPage : MySitePublicWebPartPage
{
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
Control master = base.Master;
if (master != null)
{
master = master.FindControl("PlaceHolderTopNavBar");
}
if (master != null)
{
master = master.FindControl("PlaceHolderHorizontalNav");
}
if (master != null)
{
master = master.FindControl("TopNavigationMenu");
}
if (master != null)
{
master.Visible = true;
}
}
}
You will notice that all I did was reverse what the code was doing by setting the visible property of the top menu to true. After I compiled my code I went to the new site template that I created and changed the inherits clause to point to my code behind instead of Microsoft’s. After adding my assembly to the GAC and an IISRESET, I was able to see tabs!