Reputation: 689
I have a website with Page A and Page B
Page B has a Link on Page A
Page B is actually a sub-sub-sub-web of Page C.
Now I am trying to make changes to Breadcrumb Navigation which is a custom User Control.
ATM I am trying to check if user is navigated to Page B from Page A then create this navigation and If Navigated from somewhere otherwise build a different Navigation. By using this property I know where a user coming from
Request.UrlReferrer.ToString()
OK Now problem is I want to build or get Site Map of Page/web a User is navigated from so that I can add this page B title to that Breadcrumb navigation as shown below,
Page A > Page B
or it can be
Page C > Page C.1 > Page C.2 > Page B
code I am using is this,
string defaultBreadcrumbHtml = "<SPAN><a class=\"ms-sitemapdirectional\" href=\"{0}\">{1}</a></SPAN>";
string defaultSpacingHtml = "<SPAN> > </SPAN>";
protected void Page_Load(object sender, EventArgs e)
{
try
{
SiteMapProvider contentMapProvider = SiteMap.Providers["SPContentMapProvider"];
StringBuilder generatedHTML = new StringBuilder();
generatedHTML.Append("<div class=\"ms-globallinks TopBreadcrumbs\">");
if (contentMapProvider != null)
{
SiteMapNode currentNode = contentMapProvider.FindSiteMapNode(Request.UrlReferrer.ToString());
if (currentNode != null)
{
string[] breadcrumbTitles = new string[20]; ;
string[] breadcrumbUrls = new string[20];
int count = 0;
if (currentNode == contentMapProvider.RootNode)
{
breadcrumbTitles[0] = currentNode.Title;
breadcrumbUrls[0] = currentNode.Url;
}
else
{
while (currentNode != contentMapProvider.RootNode)
{
if (Request.UrlReferrer.ToString().Contains("PageA"))
{
breadcrumbTitles[count] = "Page B";
breadcrumbUrls[count] = string.Format("www.Gohome.com\PageB.aspx");
count++;
}
breadcrumbTitles[count] = currentNode.Title;
breadcrumbUrls[count] = currentNode.Url;
if (currentNode.ParentNode != null)
{
currentNode = currentNode.ParentNode;
count++;
}
else
{
break;
}
}
breadcrumbTitles[count] = currentNode.Title;
breadcrumbUrls[count] = currentNode.Url;
}
while (count >= 0)
{
generatedHTML.Append(string.Format(defaultBreadcrumbHtml, breadcrumbUrls[count], breadcrumbTitles[count]));
if (count != 0)
{
generatedHTML.Append(defaultSpacingHtml);
}
count--;
}
generatedHTML.Append("</div>");
html.Text = generatedHTML.ToString();
}
}
But its not working properly, I tried to debug it but because I am not able to get Site Map of Web/page I came from, I am not able to get site map. So My question is, How can I get Site Map of Website I am navigated from , so that I add another Node to it as "siteicame from > ..> Page B"
to get Site Map of current page i can use this but I dont want to use this as It will give SiteMap as Site C > Site C.1 ... > Site B
Cheers
Upvotes: 2
Views: 891
Reputation: 1007
To achieve Breadcrumb navigation ... No need of code behind.
You can achieve through
1) Web.SiteMap 2) ASPX Page's Tabs
If you want... i will show you sample code... ?
Upvotes: 1