This worked great!
One more thing... the sitemap here just captures the ablecommerce store. Is there any code i can add that will bring in the other sites I have? Able is my store, but i have lots of other static pages for educational purposes.
Thanks,
Brian
You can accomplish this in two ways.
1)- There is a method named
PopulateCommonUrls in
App_Code/CommonSiteMapProvider.cs file.
Code: Select all
private void PopulateCommonUrls(List<SiteMapUrl> siteMapItems, SiteMapOptions options)
{
siteMapItems.Add(new SiteMapUrl(GetAbsoluteUrl("~/Default.aspx"), options.DefaultChangeFrequency, options.DefaultUrlPriority));
siteMapItems.Add(new SiteMapUrl(GetAbsoluteUrl("~/ContactUs.aspx"), options.DefaultChangeFrequency, options.DefaultUrlPriority));
siteMapItems.Add(new SiteMapUrl(GetAbsoluteUrl("~/AboutUs.aspx"), options.DefaultChangeFrequency, options.DefaultUrlPriority));
}
and can update this method to generate the URL for your custom pages. For example if you have a page custompage.aspx and want it to include in site map then you have to change the method as below
Code: Select all
private void PopulateCommonUrls(List<SiteMapUrl> siteMapItems, SiteMapOptions options)
{
siteMapItems.Add(new SiteMapUrl(GetAbsoluteUrl("~/Default.aspx"), options.DefaultChangeFrequency, options.DefaultUrlPriority));
siteMapItems.Add(new SiteMapUrl(GetAbsoluteUrl("~/ContactUs.aspx"), options.DefaultChangeFrequency, options.DefaultUrlPriority));
siteMapItems.Add(new SiteMapUrl(GetAbsoluteUrl("~/AboutUs.aspx"), options.DefaultChangeFrequency, options.DefaultUrlPriority));
siteMapItems.Add(new SiteMapUrl(GetAbsoluteUrl("~/custompage.aspx"), options.DefaultChangeFrequency, options.DefaultUrlPriority));
}
2)- If you want to auto generate the URL for all root pages then you can create a new function in the class just under the
PopulateCommonUrls method and use it to generate the URLs for static pages in site map.
Code: Select all
private void PopulateStaticUrls(List<SiteMapUrl> siteMapItems, SiteMapOptions options)
{
string url = "~/";
string path = HttpContext.Current.Server.MapPath(url);
String[] files = Directory.GetFiles(path,"*.aspx",SearchOption.TopDirectoryOnly);
foreach (string file in files)
{
FileInfo fileInfo = new FileInfo(file);
siteMapItems.Add(new SiteMapUrl(GetAbsoluteUrl(GetAbsoluteUrl("~/"+fileInfo.Name)), options.DefaultChangeFrequency, options.DefaultUrlPriority));
}
}
after adding this method you will need to make some change in code. So locate the
Code: Select all
PopulateCommonUrls(siteMapItems, options);
and make it look like
Code: Select all
//PopulateCommonUrls(siteMapItems, options);
PopulateStaticUrls(siteMapItems, options);
Note that I have commented the call to
PopulateCommonUrls because now our custom method will generate URLs for all root pages.
One more thing as adding all the root pages to the site map would not be a desired operation. So it would be better that you use some slandered name prefix for the custom pages. For example "Custom_MyPage.aspx". This means that all your custom pages names are prefixed now so you can update your custom function to generates the links for those pages as below
Code: Select all
private void PopulateStaticUrls(List<SiteMapUrl> siteMapItems, SiteMapOptions options)
{
string url = "~/";
string path = HttpContext.Current.Server.MapPath(url);
String[] files = Directory.GetFiles(path, "Custom_*.aspx", SearchOption.TopDirectoryOnly);
foreach (string file in files)
{
FileInfo fileInfo = new FileInfo(file);
siteMapItems.Add(new SiteMapUrl(GetAbsoluteUrl(GetAbsoluteUrl("~/"+fileInfo.Name)), options.DefaultChangeFrequency, options.DefaultUrlPriority));
}
}
and finally update the call to this function by locating the
Code: Select all
PopulateCommonUrls(siteMapItems, options);
and make it look like
Code: Select all
PopulateCommonUrls(siteMapItems, options);
PopulateStaticUrls(siteMapItems, options);
Note now there is no need to comment the
PopulateCommonUrls method call because now our custom method will only add custom pages to site map not all.