1

My website has dynamic content, new links are being created.

my db has a table which pretty much contains all the added urls.

So my question is how importnt is it for me to have sitemaps.xml, and also is there a simple way to build it so that when new links are generated i can tag it to the end of a sitemap.xml file?

2 Answers 2

2

You can use LINQ to XML to create an XML sitemap from your database, then return the sitemap from an action by returning Content(document.ToString(), "text/xml").

Sign up to request clarification or add additional context in comments.

10 Comments

the problem is how do i go about newly added urls, because i dont want it to have to loop through all the urls's everytime the crawler hits it.
@raklos: You should loop through the URLs every time. There's nothing wrong with that.
If you really want to, you can run code that writes the file to disk whenever the database is changed, but I wouldn't recommend it.
if i choose your way, would displaying just the previous weeks links be enough? - as in google will still have records of older links. also instead of linq to xml could i populate the xml within a razor view?
@raklos: No; you should always list all links. There is no point in using Razor here; it would be easier to use LINQ to XML to generate a string. However, you can if you want to.
|
2

It is important for crawlers to be able to crawl your site quicker and with more accurate.

You can create a controller, say siteMapController and in Index add the following

 public ActionResult Index() {
        var xmlString =
            "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">";

        xmlString +=
                "<url>" +
               "<loc>Your site</loc>" +
               "<changefreq>weekly</changefreq>" +
               "<priority>0.6</priority>" +
             "</url>" +
           "<url>" +
                    "<loc>Static Link of you site</loc>" + //you can add as many you want
                       "<changefreq>weekly</changefreq>" +
                       "<priority>0.6</priority>" +
                    "</url>" +
                    "<url>";


           //Dynamic links
            xmlString += "<url>" +
                         "<loc>Link of new item"</loc>" +
                         "<lastmod>" + DateTime.Now.ToString("yyyy-MM-dd") + "</lastmod>" +
                         "<changefreq>daily</changefreq>" +
                         "<priority>0.8</priority>" +
                         "</url>";
        }
        xmlString += "</urlset>";
        ViewData["siteMap"] = xmlString;
        return View();
    }

save the xml on your server and post the sitemap via this link

https://www.google.com/webmasters/tools/home?hl=en

hope that helps

2 Comments

What if you have 20,000 dynamically generated pages on your site? Should you include them all in the site map, or will Google disregard such a large entry. Also, you should generally avoid building XML via string concatenation. Either write directly to the response stream or use the XML APIs or a StringBuilder in the worst case.
okay so this will giveme an xml file at mysite.com/sitemap ? the problem is, when newly created links are added to the db will i have to rerender the entire xml file?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.