0
votes

i am developing a website and there i am showing so breadcrumbs using web.sitemap.

the problem which i facing is basically that i have some hard pages and soft pages which are only mentioned in database now when i click on hard pages it show full breadcrumbs also including that main page which contain it but when i like on that link which is in database and i have to show it on one particular page is used for every page data not include the main page.for example

this is for hard pages

home > main menu > hard page

but when i click on soft pages which are in database it

home > soft page

i want to set it dynamically using c# is there anyone who know how to fix?

1

1 Answers

3
votes

An example how to roll out your own XmlSiteMapProvider with custom logic:

    public class MyXmlSiteMapProvider : XmlSiteMapProvider
    {
        public override SiteMapNode FindSiteMapNode(string rawUrl)
        {
            SiteMapNode node = base.FindSiteMapNode(rawUrl);
            if (node != null)
            {
                var page = HttpContext.Current.Handler as Page;
                if (page != null)
                {
                    page.Title = node.Title;
                }
                var newNode = node.Clone(true);
                newNode.Url = rawUrl;
                return newNode;
            }
            else
            {
                return null;
            }
        }

        public override bool IsAccessibleToUser(HttpContext context, SiteMapNode node)
        {
            if (node.Roles.OfType<string>().Any(r => String.Equals(r, "*", StringComparison.Ordinal) || context.User.IsInRole(r)))
            {
                return true;
            }
            else
            {
                throw new InsufficientRightsException();
            }
        }
    }

Installing into Web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.web>
        <siteMap defaultProvider="MyXmlSiteMapProvider" enabled="true">
            <providers>
                <clear />
                <add name="MyXmlSiteMapProvider" type="MyXmlSiteMapProvider" siteMapFile="Web.sitemap" securityTrimmingEnabled="true" />
            </providers>
        </siteMap>
    </system.web>
</configuration>

Use standard ASP.NET breadcrumbs control:

<asp:SiteMapPath runat="server" RenderCurrentNodeAsLink="true" SkipLinkText="" />