Category Archives: SiteMapPath

[RESOLVED] SiteMapPath with UrlRouting not working on dynamically generated routes VB

I am learning .net and I have implemented SiteMapPath on a site i'm developing which uses Url Routing. It is working fine for static routes but i am trying to get it to work on a dynamically generated route that passes a {date} and a {title} but I can't find any information on it anywhere, I have a book but it doesn't go in to SiteMapPath with UrlRouting, can someone point me in the right direction please.

I have set up routes in Global.asax file:

routes.MapPageRoute("AboutUsRoute", "about-us/", "~/aboutUs.aspx")
    routes.MapPageRoute("NewsRoute", "news/{date}/{title}", "~/news.aspx")
    routes.MapPageRoute("AreaSelectionRoute", "area-selection/", "~/areaSelection.aspx")
    routes.MapPageRoute("MobilityRoute", "mobility-solutions/", "~/mobilitySolutions.aspx")
    routes.MapPageRoute("ResourcesRoute", "resources/", "~/resources.aspx")

My web.sitemap currently looks like:

    <siteMapNode url="http://domain-name" title="Home"  description="Home">
        
        <siteMapNode url="about-us/" title="About Us"  description="About Synergy">
            <siteMapNode url="about-us/overview/" title="Overview"  description="Overview" />
            <siteMapNode url="about-us/mission-statement/" title="Mission Statement"  description="Mission Statement" />
            <siteMapNode url="about-us/membership/" title="Membership"  description="Membership" />
            <siteMapNode url="about-us/quality/" title="Quality"  description="Quality" />
            <siteMapNode url="about-us/our-ethos/" title="Our Ethos"  description="Our Ethos" />
        </siteMapNode>
        
        
        <siteMapNode url="news/{date}/{title}/" title="News"  description="News" />
        <siteMapNode url="area-selection/" title="Area Selection"  description="Area Selection" />
        <siteMapNode url="mobility-solutions/" title="Mobility Solutions"  description="Mobility Solutions" />
        <siteMapNode url="resources/" title="Resources"  description="Resources" />
        <siteMapNode url="contact-us/" title="Contact Us"  description="Contact Us" />
    </siteMapNode>

Thanks for any info.

J.

Hi,

jamm

but i am trying to get it to work on a dynamically generated route that passes a {date} and a {title}

According to your description ,I would like to suggest you to check the link below for the similar thread which provides some solutions for the same issue.

Using Web.SiteMap with Dynamic URLS (URL Routing)

Hope it can help you.

[RESOLVED] How to display thread subject

Hello, friends,

I am modifying a forum application (asp.net 3.5). This app uses web.sitemap as the following:

<siteMap enableLocalization="true" xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
    <siteMapNode url="~/Forum/Default.aspx" title="Forum page"  resourceKey="ForumPage" description="Forum page with groups and forums.">
        <siteMapNode url="~/Forum/ViewForum.aspx" title="View Forum page"  resourceKey="ViewForumPage" description="View Forum page">
            <siteMapNode url="~/Forum/ViewTopic.aspx" title="View Topic page"  resourceKey="ViewTopicPage" description="View Topic page" />
        </siteMapNode>
        <siteMapNode url="~/Forum/Register.aspx" title="Register page"  resourceKey="RegisterPage" description="Register page" />
    </siteMapNode>
</siteMap>

and displays site map path as the following:

Skip Navigation LinksForums » View Forum » View Topic

Now, we want improve it: When a user clicks on any thread in thie Topic page, we want the siteMapPath to be displayed as the following:

Forums » View Forum » View Topic » How to find all prime numbers under 1000 (i.e., the thread subject).

How to make this happen? Any reference paper, snippet? Thanks a lot!

Hi,

According to your description ,for my experience you can use SiteMapResolveEventHandler Delegate to achieve the goal.

Here is a sample ,hope it can help you.

Code in ViewTopic page(~/Forum/ViewTopic.aspx):

.aspx:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:SiteMapPath ID="SiteMapPath1" runat="server" SkipLinkText="Skip Menu" RootNodeStyle-Font-Names="Verdana"
            RootNodeStyle-ForeColor="Orange" RootNodeStyle-BorderWidth="2">
        </asp:SiteMapPath>
        <br/>
        <br/>
        <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">subject_xm1</asp:LinkButton>
        <asp:LinkButton ID="LinkButton2" runat="server" OnClick="LinkButton2_Click">subject_xm2</asp:LinkButton>
        <asp:LinkButton ID="LinkButton3" runat="server" OnClick="LinkButton3_Click">subject_xm3</asp:LinkButton>
    </div>
    </form>
</body>
</html>


 

.cs:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
        }
    }
    private SiteMapNode ExpandForumPaths(Object sender, SiteMapResolveEventArgs e)
    {
        SiteMap.SiteMapResolve -= new SiteMapResolveEventHandler(this.ExpandForumPaths);
        SiteMapNode currentNode = SiteMap.CurrentNode.Clone(true);
        SiteMapNode tempNode = currentNode;
        if (tempNode != null)
        {
            // You can use the value of Request.QueryString["p"].ToString() to show the different thread subject.
            // For example,you can search the record in database by using the value as a condition and get the title of thread subject.
            // tempNode.Title = tempNode.Title + thread subject title.
            tempNode.Title = tempNode.Title + " > Subject_xm"+Request.QueryString["p"].ToString();
        }
        return currentNode;
    }
    public void Bind()
    {
        string url_full = HttpContext.Current.Request.Url.PathAndQuery.ToString();
        string[] urls = url_full.Split('?');
        if (urls.Length > 1)
        {
            SiteMap.SiteMapResolve += new SiteMapResolveEventHandler(this.ExpandForumPaths);
        }
        else
        {
            Response.Write("please click the link button below to redirect to different thread subject page");
        }
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Response.Redirect(HttpContext.Current.Request.Path + "?p=1");
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        Response.Redirect(HttpContext.Current.Request.Path + "?p=2");
    }
    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        Response.Redirect(HttpContext.Current.Request.Path + "?p=3");
    }
       

Code in .sitemap:(the same as you mentioned):

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
  <siteMapNode url="~/Forum/Default.aspx" title="Forum page"  resourceKey="ForumPage" description="Forum page with groups and forums.">
    <siteMapNode url="~/Forum/ViewForum.aspx" title="View Forum page"  resourceKey="ViewForumPage" description="View Forum page">
      <siteMapNode url="~/Forum/ViewTopic.aspx" title="View Topic page"  resourceKey="ViewTopicPage" description="View Topic page" />
    </siteMapNode>
    <siteMapNode url="~/Forum/Register.aspx" title="Register page"  resourceKey="RegisterPage" description="Register page" />
  </siteMapNode>
</siteMap>


Please check the link below for more information about SiteMapResolveEventHandler Delegate:

http://msdn.microsoft.com/en-us/library/system.web.sitemapresolveeventhandler.aspx



Hello,



Considering that many developers in this forum ask how to display
the breadcrumbs by using site map while the page's URL with different
parameters, my team has created a code sample for this frequently asked programming
task in
Microsoft All-In-One Code Framework. You
can download the code samples at:



 



CSASPNETBreadcrumbWithQueryString



 http://bit.ly/CSASPNETBreadcrumbWithQueryString



 



With these code samples, we hope to reduce developers’ efforts in
solving the frequently asked



programming tasks. If you have any feedback or suggestions for the
code samples, please email us:
onecode@microsoft.com.



------------



The Microsoft All-In-One Code Framework (http://1code.codeplex.com)
is a free, centralized code sample library driven by developers' needs. Our goal is to provide typical code samples for all Microsoft development technologies, and reduce developers' efforts in solving typical programming tasks.



Our team listens to developers’ pains in MSDN forums, social media
and various developer communities. We write code samples based on developers’
frequently asked programming tasks, and allow developers to
download them with a short code sample
publishing cycle. Additionally, our team offers
a free code sample
request service
. This service is a proactive way for
our developer community to obtain code samples for certain programming tasks directly
from Microsoft.



Thanks



Microsoft All-In-One Code Framework



[RESOLVED] How to get breadcrumbs (site map) if same page is having different url

Hi,

sitemap breadcrumb is based on url of pages.actual url is compared with the url stored in sitemap file. But suppose i have navigation to same page  but with different url( in case of passing query string )  then in that case it creates problem.Breadcrum is not created.

How to solve this problem ?

You can build a custom site map provider.

Please see this artile.


Can anyone tell how breadcrumbs was created for this web site ?You can for each thread there is different query string, with different kay-value pair.How breadcrumbs were created in this asp.net forum ?please can anyone tell ? 

Code behind part is confusing.Nothing is explained.Can you tell something in that code ? 

Charith Gunasekara

You can build a custom site map provider.

Please see this artile.


 

What is "queryStringToInclude" in that code ?What should i write in place of that ?

Hi,

shyam_oec

sitemap breadcrumb is based on url of pages.actual url is compared with the url stored in sitemap file. But suppose i have navigation to same page  but with different url( in case of passing query string )  then in that case it creates problem.Breadcrum is not created.

 

According to your description ,for my experience you can try to use SiteMapResolveEventHandler Event,here is a sample ,hope it can help you.

1.Code in web.sitemap:

<?xml version="1.0" encoding="utf-8" ?>
<siteMap>
  <siteMapNode
    title="Forum Group"
    description="Forum Group List"
    url="~/SiteMapBreadcrumbs.aspx?Shop=Default">
    <siteMapNode
      title="Test"
      description="Forum List"
     url="~/Forms/Test.aspx">
      <siteMapNode
        title="Post"
        description="Post List"
        url="~/SiteMapBreadcrumbs_2.aspx" />
    </siteMapNode>
  </siteMapNode>
</siteMap>


2.Code in page which named 'SiteMapBreadcrumbs_2.aspx' .

.aspx:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     <asp:SiteMapPath ID="SiteMapPath1" runat="server" SkipLinkText="Skip Menu" RootNodeStyle-Font-Names="Verdana"
            RootNodeStyle-ForeColor="Orange" RootNodeStyle-BorderWidth="2">
        </asp:SiteMapPath>
    </div>
    </form>
</body>
</html>


3.Code in page (SiteMapBreadcrumbs_2.aspx.cs):

  protected void Page_Load(object sender, EventArgs e)
    {
        Bind();
    }
    private SiteMapNode ExpandForumPaths(Object sender, SiteMapResolveEventArgs e)
    {
        SiteMap.SiteMapResolve -= new SiteMapResolveEventHandler(this.ExpandForumPaths);
        SiteMapNode currentNode = SiteMap.CurrentNode.Clone(true);
        SiteMapNode tempNode = currentNode;
        if ((tempNode = tempNode.ParentNode) != null)
        {
            tempNode.Title = "Test_" + Session["id"];
            tempNode.Url = "~/Forms/Test" + Session["id"] + ".aspx";
        }
        return currentNode;
    }
    public void Bind()
    {
        if (Request.QueryString["id"] !=null)
        {
            Session["id"] = Request.QueryString["id"];
            SiteMap.SiteMapResolve += new SiteMapResolveEventHandler(this.ExpandForumPaths);
        }
        else
        {
            Response.Write("please enter the url which contains the extra URL parameters(id)");
        }
    }          

By the way,do not forget the code in web.config:

<system.web>

<siteMap defaultProvider="XmlSiteMapProvider" enabled="true">
   <providers>
    <remove name="XmlSiteMapProvider"/>
    <add name="XmlSiteMapProvider" description="SiteMap provider which reads in .sitemap XML files." type="System.Web.XmlSiteMapProvider " siteMapFile="Web.sitemap" securityTrimmingEnabled="true"/>
   </providers>
  </siteMap>
 </system.web>

 I would like to suggest you that please check the link below for more information about SiteMap.SiteMapResolve Event.

http://msdn.microsoft.com/en-us/library/system.web.sitemap.sitemapresolve.aspx

 Here are some similar threads:

http://forums.asp.net/p/1599976/4074987.aspx

http://forums.asp.net/p/1590166/4035125.aspx



Hello,



Considering that many developers in this forum ask how to display
the breadcrumbs by using site map while the page's URL with different
parameters, my team has created a code sample for this frequently asked programming
task in
Microsoft
All-In-One Code Framework
. You can download the code samples
at:



 



CSASPNETBreadcrumbWithQueryString



 http://bit.ly/CSASPNETBreadcrumbWithQueryString



 



With these code samples, we hope to reduce developers’ efforts in
solving the frequently asked



programming tasks. If you have any feedback or suggestions for the
code samples, please email us:
onecode@microsoft.com.



------------



The Microsoft All-In-One Code Framework (http://1code.codeplex.com) is a free, centralized code sample library driven by developers' needs. Our goal is to provide typical code samples for all Microsoft development technologies, and reduce developers' efforts in solving typical programming tasks.



Our team listens to developers’ pains in MSDN forums, social media
and various developer communities. We write code samples based on developers’
frequently asked programming tasks, and allow developers to
download them
with a short code sample publishing cycle. Additionally, our team offers
a free code sample request service. This
service is a proactive way for our developer community to obtain code samples
for certain programming tasks directly from Microsoft.



Thanks



Microsoft All-In-One Code Framework



[RESOLVED] Assign dynamic URL to siteMapNode

 HI All,

I have Sitemap with Node,

<siteMapNode url="Forms/Test.aspx" title="Test" description="Test" />

I want to assign url to the siteMapNode dynamically depending upon condition eg.

if(id == 1)

<siteMapNode url="Forms/Test1.aspx" title="Test" description="Test" />

if(id == 2)

<siteMapNode url="Forms/Test2.aspx" title="Test" description="Test" />

Thanks in advance.

Hi,

According to your description ,you can try as below by using SiteMapResolveEventHandler method ,here is a sample ,hope it can help you.

1.Code in web.sitemap:

<?xml version="1.0" encoding="utf-8" ?>
<siteMap>
  <siteMapNode
    title="Forum Group"
    description="Forum Group List"
    url="~/SiteMapBreadcrumbs.aspx?Shop=Default">
    <siteMapNode
      title="Test"
      description="Forum List"
     url="~/Forms/Test.aspx">
      <siteMapNode
        title="Post"
        description="Post List"
        url="~/SiteMapBreadcrumbs_2.aspx" />
    </siteMapNode>
  </siteMapNode>
</siteMap>


2.Code in page which named 'SiteMapBreadcrumbs_2.aspx' .

.aspx:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     <asp:SiteMapPath ID="SiteMapPath1" runat="server" SkipLinkText="Skip Menu" RootNodeStyle-Font-Names="Verdana"
            RootNodeStyle-ForeColor="Orange" RootNodeStyle-BorderWidth="2">
        </asp:SiteMapPath>
    </div>
    </form>
</body>
</html>


3.Code in page (SiteMapBreadcrumbs_2.aspx.cs):

  protected void Page_Load(object sender, EventArgs e)
    {
        Bind();
    }
    private SiteMapNode ExpandForumPaths(Object sender, SiteMapResolveEventArgs e)
    {
        SiteMap.SiteMapResolve -= new SiteMapResolveEventHandler(this.ExpandForumPaths);
        SiteMapNode currentNode = SiteMap.CurrentNode.Clone(true);
        SiteMapNode tempNode = currentNode;
        if ((tempNode = tempNode.ParentNode) != null)
        {
            tempNode.Title = "Test_" + Session["id"];
            tempNode.Url = "~/Forms/Test" + Session["id"] + ".aspx";
        }
        return currentNode;
    }
    public void Bind()
    {
        if (Request.QueryString["id"] !=null)
        {
            Session["id"] = Request.QueryString["id"];
            SiteMap.SiteMapResolve += new SiteMapResolveEventHandler(this.ExpandForumPaths);
        }
        else
        {
            Response.Write("please enter the url which contains the extra URL parameters(id)");
        }
    }          

By the way,do not forget the code in web.config:

<system.web>

<siteMap defaultProvider="XmlSiteMapProvider" enabled="true">
   <providers>
    <remove name="XmlSiteMapProvider"/>
    <add name="XmlSiteMapProvider" description="SiteMap provider which reads in .sitemap XML files." type="System.Web.XmlSiteMapProvider " siteMapFile="Web.sitemap" securityTrimmingEnabled="true"/>
   </providers>
  </siteMap>
 </system.web>



Hello,



Considering that many developers in this forum ask how to display
the breadcrumbs by using site map while the page's URL with different
parameters, my team has created a code sample for this frequently asked programming
task in
Microsoft
All-In-One Code Framework
. You can download the code samples
at:



 



CSASPNETBreadcrumbWithQueryString



 http://bit.ly/CSASPNETBreadcrumbWithQueryString



 



With these code samples, we hope to reduce developers’ efforts in
solving the frequently asked



programming tasks. If you have any feedback or suggestions for the
code samples, please email us:
onecode@microsoft.com.



------------



The Microsoft All-In-One Code Framework (http://1code.codeplex.com) is a free, centralized code sample library driven by developers' needs. Our goal is to provide typical code samples for all Microsoft development technologies, and reduce developers' efforts in solving typical programming tasks.



Our team listens to developers’ pains in MSDN forums, social media
and various developer communities. We write code samples based on developers’
frequently asked programming tasks, and allow developers to
download them
with a short code sample publishing cycle. Additionally, our team offers
a free code sample request service. This
service is a proactive way for our developer community to obtain code samples
for certain programming tasks directly from Microsoft.



Thanks



Microsoft All-In-One Code Framework