Creating a web.sitemap file for an ASP.NET website

I am trying to implement palette functionality on Visual Studio ASP C # using SiteMapPath Control.

The company I'm working on has inherited the site, and we are primarily PHP developers, so forgive ignorance.

Initially, when I fell into SiteMapPath from the tool window, I received an error message in which there was no web.sitemap file found. Then I created one using an application that supposedly does the job for ASP sites.

The error message we receive now tells us that you are not allowed to have the same URL twice in the xml structure. This seems rather ridiculous, as many pages will have the same links.

In some studies, I was asked to add each URL with a unique virtual useless requeststring string in xml. It also seems a bit ridiculous, and a common hack - especially with a site containing potentially hundreds of URLs.

Can someone shed some light on this, or maybe even on a completely different approach?

Thank you very much!

+4
source share
2 answers

"The error message we get now tells us that you are not allowed to have the same URL twice in the xml structure. This seems pretty ridiculous as many pages will have the same links."

I think there is a bit of confusion: pages with the same links do not matter - web.sitemap is just an XML map of the page locations. The file does not record cross-references to pages. But you can nest things like that if they have the same name:

<?xml version="1.0" encoding="utf-8" ?> <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" > <siteMapNode url="/" title="Home"> <siteMapNode url="/subdir" title="Subdir"> <siteMapNode url="/subdir/page.aspx" title="Nested Page" /> </sitemapNode> <siteMapNode url="/page.aspx" title="Root Page" /> </siteMapNode> </siteMap> 
0
source

Basically, the default site map provider ( System.Web.XmlSiteMapProvider ) requires all URLs to be unique, so it can easily resolve the currently selected node with the SiteMap.CurrentNode property.

This is a bit disappointing, which leads to people encountering dummy query strings, as you already noted. For a simple case with multiple duplicates, this is usually acceptable.

However, you can implement your own site map provider, see Implementing ASP.NET Site-Map Providers on MSDN. By doing this, you can have your own logic that processes your Sitemap and get the behavior you need.

In this case, perhaps the easiest approach would be to have a custom Sitemap provider.

+3
source

Source: https://habr.com/ru/post/1383454/


All Articles