There are time when you are going to deploy your
website on production and client want Sitemap file of website. Sitemap file is
used to improve SEO results.
Sometimes client have some weird requirement that
create XML sitemap dynamically for Sitecore website.
For this type of requirement, always keep one field
"Show Sitemap" in all the page content.
Here is a code to generate sitemap dynamically.
Remember you need a permission to update Sitemap.xml file on server.
public bool GenerateXml(List<Tuple<string, string, string>> lstTuples)
//generateXml
{
bool result = false;
string xmlFile = HttpContext.Current.Server.MapPath("/Sitemap.xml");
XmlTextWriter writer = new XmlTextWriter(xmlFile, System.Text.Encoding.UTF8);
writer.Formatting = Formatting.Indented;
writer.WriteStartDocument();
{
writer.WriteStartElement("urlset");
writer.WriteAttributeString("xmlns:xhtml", "http://www.w3.org/1999/xhtml");
writer.WriteAttributeString("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");
string url = "http://" + System.Web.HttpContext.Current.Request.ServerVariables["HTTP_HOST"];
foreach (var value in lstTuples)
{
writer.WriteStartElement("url");
writer.WriteElementString("loc",
System.Web.HttpUtility.HtmlEncode(url
+ value.Item2));
writer.WriteElementString("lastmod", value.Item3);
writer.WriteElementString("changefreq", "weekly");
writer.WriteElementString("priority", "0.5");
writer.WriteEndElement();
}
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
result = true;
}
return result;
}
Pass the Tuple collection which contains URL and last
modified date of content items.
This code should create file with below data
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://test/</loc>
<lastmod>2015-04-06</lastmod>
<changefreq>weekly</changefreq>
<priority>0.5</priority>
</url>
<url>
<lastmod>2015-03-23</lastmod>
<changefreq>weekly</changefreq>
<priority>0.5</priority>
</url>
Please leave your comments or share this code if it’s
useful for you.
It does not need to be a static Sitemap.xml file. You can call it anything. Important thing is that you tell on robots.txt where it is located. Just make an item and add layout to it and then just dynamically load it. For example /sitemapxml.aspx. All you need to make sure is this should load in less than 30 secs or Googlebot will give up.
ReplyDeletec
ReplyDeleteWhether somebody pursuit of his vital thing, hence he or she desires to be accessible that at length, hence that thing is maintained over here.
ReplyDeleteMinistry of Freedom bonus
The team was responsive, professional, and easy to work with best brand agencies. Their strong deliverables and project management best branding agency have also secured continued engagement.
ReplyDeleteThey successfully delivered the marketing and UX design companies websites to the delight of the sales team. Their strong expertise informed painful decision industrial ui services making and strategy.
ReplyDeleteIt’s a brilliant platform concerning one of our primary issues! weed scale
ReplyDeleteCommunication issues haven't disrupted the premium niche edit project timeline or impacted the quality of end-deliverables.
ReplyDeleteThe stated web site is like a first rate help for all the humans attempting to connect with a person like them, for similar records take a look at their internet site! They may be incredible!
ReplyDeletewebsite design company
Their team communicated with designers and exceeded expectations. They also helped with market research.
ReplyDeletetop branding companies
Their communication skills and reliable contact were features of the collaboration
ReplyDeletedigital branding agency
Their transparency, best app design companies and technical know-how make them a valuable partner.
ReplyDeleteThey are miraculously speedy within the response of the requests!
ReplyDeleteuser experience agency
They delivered top-notch, thorough results that demonstrated expertise and careful attention of detail.
ReplyDeletebranding agency
They clearly communicate project changes and updates, and the entire team was professional.
ReplyDeletebranding studio
They were communicative and responsive, and they were always available to answer questions.
ReplyDeletebest user experience design
The quality of your blogs and conjointly the articles and price appreciating.
ReplyDeletedesign consultancies San Francisco
I really love your write-ups guys continue the good work.
ReplyDeletebrand design firm
Well, it’s a nice one, I have been looking for. Thanks for sharing such informative stuff.
ReplyDeleteapp designing companies
Hey enormous stuff or pleasant information you are offering here.
ReplyDeletelogo design firm
This written piece gives fastidious understanding yet.It’s amazing in support of me to truly have a web site that is valuable meant for my knowledge
ReplyDeletetop web agencies
Big thanks to you for sharing such great information.
ReplyDeletebest web design company
I see the greatest contents on your blog and I extremely love reading them.
ReplyDeleteBay Area web designer
I have checked this link this is really important for the people to get benefit from.
ReplyDeleteUI UX design companies
I wanna thanks to a great extent for providing such informative and qualitative material therefore often.
ReplyDeleteUI design firm
Whether somebody pursuit of his vital thing, hence he or she desires to be accessible that at length, hence that thing is maintained over here.
ReplyDeleteproduct designing companies
Thank you I am glad about the encouragement! I love your site, you post outstanding.
ReplyDeletemobile app companies
I'd be trampled if all sites gave articles like these awesome articles.
ReplyDeletebest UX agencies
Thanks to share these details it’s truly nice.
ReplyDeletetop UI designers
I don’t waste my free time that’s why I read the informative things when I got this blog I really enjoyed reading this.
ReplyDeleteBrand Booster US
While the allure of YouTube Cash Cow success is tempting, there are several common pitfalls that aspiring creators should be aware of. From neglecting quality content to focusing solely on monetization, these missteps can hinder long-term growth. By understanding and avoiding these pitfalls, you can set your YouTube Cash Cow journey on the path to success.
ReplyDelete