is there a best practices on how to create a sitemap for Umbraco v6 using MVC rendering engine.
I tried a lot, but no solution I have 2 problems: 1. I created a template called sitemap, then i tried to access the template through example.com/sitemap (altTemplate), but cant make to work like >> example.com/sitemap.xml !
2. cant include the homepage (most parent node ) to the iteration !
Now it would be easy to include this in a view and it would render the required markup however there is a further complication, we need the response header content type to be "text/xml", this requires a SurfaceController:
My file is in /Controllers/XmlSitemapSurfaceController.cs but if you don't have a VS.NET solution, place the file in the /App_Code/XmlSitemapSurfaceController.cs location
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Web;
using System.Web.Mvc;
using Umbraco.Web.Mvc;
namespace MyNameSpace.Controllers
{
public class XmlSitemapSurfaceController : SurfaceController
{
public ActionResult Index()
{
Response.ContentType = "text/xml";
return PartialView("XmlSitemap",CurrentPage);
}
}
}
Ok, so now assuming you are requesting your xml sitemap by alttemplate (so you don't need a node) e.g. /XmlSitemap/ we can now rewrite this using a IIS7 Rewrite rule (this extension must be installed in your IIS)
Add this to your web.config within the system.webServer element:
I forgot to mention that "isDataNode" is a convention that we use for Nodes that should always be ignored by sitemaps and navigation's etc, we add it as a label property to all document types that we know should always be ignored, kind of like a enforced umbracoNaviHide.
Your xml sitemap is perfect however you have <meta name="robots" content="noindex"> on most pages while this is in place Google will not index these pages. You should change it to <meta name="robots" content="index,follow">
Unfortunity, promoto.ae only indexed my home page but not the others!
why is that happening? is it because the sitemap.xml showing the page un defined (e.g. promoto.ae/about-us) there's no html or something?
This is the message from Google webmaster: Googlebot couldn't crawl this URL because it points to a non-existent page. Generally, 404s don't harm your site's performance in search, but you can use them to help improve the user experience. More info.
Another note: Usually when you copy a text from the home page and past it into Google, the links if that text should appear. but if i copy text from inside promoto.ae home page, google won't results! so basically non of the pages are indexing!
This is a great thread and it got me a working XML sitemap. I would like to enhance it further to include the lastmod property. In XSLT I would have used the following:
SiteMap for Umbraco V6.x MVC Engine
Hi,
is there a best practices on how to create a sitemap for Umbraco v6 using MVC rendering engine.
I tried a lot, but no solution
I have 2 problems:
1. I created a template called sitemap, then i tried to access the template through example.com/sitemap (altTemplate), but cant make to work like >> example.com/sitemap.xml !
2. cant include the homepage (most parent node ) to the iteration !
please take a look at my code and advice
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
@traverse(@Model.Content.AncestorOrSelf())
</urlset>
@{Response.ContentType = "application/rss+xml";Response.Charset = "utf-8";}
@helper traverse(dynamic node)
{var nodes = node.Children;
foreach (var n in nodes)
{var loc = HttpContext.Current.Request.ServerVariables["HTTP_HOST"] + n.Url;
<url>
<loc>@loc</loc>
<lastmod>@n.UpdateDate.ToString("yyyy-MM-dd")</lastmod>
</url>
@traverse(n)
}
}
Hi Firas,
1. I would recommend using a IIS rewrire rule to do this, e.g Rewrite sitemap.xml to /xml-sitemap
2. Take a look at the NavIt package which can be used to generate a page based sitemap, it could be easily adapted to out xml instead.
Hope that's helpful?
Jeavon
Hi Jeavon,
thanks a lot,
it seems really usefull package.
but actually i got HTML sitemap not XML sitemap http://promoto.ae/sm
and the most important i cant find a solution in umbraco, is to create http://promoto.ae/sitemap.xml with MVC + Razor
thanks again.
Firas
Ok, so firstly to create a partial that will return your tree with the correct elements for a xml sitemap:
My file is /Views/Partials/XmlSitemap.cshtml
Now it would be easy to include this in a view and it would render the required markup however there is a further complication, we need the response header content type to be "text/xml", this requires a SurfaceController:
My file is in /Controllers/XmlSitemapSurfaceController.cs but if you don't have a VS.NET solution, place the file in the /App_Code/XmlSitemapSurfaceController.cs location
The final part is to render this from your view.
My file /Views/XmlSitemap.cshtml
Now either attach this view to a content node or request it as a alttemplate. e.g http://www.mysite.com/XmlSitemap and you should see the xml sitemap.
I will address how to rewrite this to sitemap.xml separately! :-)
Ok, so now assuming you are requesting your xml sitemap by alttemplate (so you don't need a node) e.g. /XmlSitemap/ we can now rewrite this using a IIS7 Rewrite rule (this extension must be installed in your IIS)
Add this to your web.config within the system.webServer element:
I forgot to mention that "isDataNode" is a convention that we use for Nodes that should always be ignored by sitemaps and navigation's etc, we add it as a label property to all document types that we know should always be ignored, kind of like a enforced umbracoNaviHide.
Thanks a lot,
it is just works :D
Hi Guys,
It worked and has been submited into Google webmaster, but its still not appearing in Google search results!
If you type in Google
Site:promoto.ae
you will notice that's there's only two indexed pages, which on of them is promoto.ae/sm
so i think we still didn't do it right.
Hi Molham,
Your xml sitemap is perfect however you have
<meta name="robots" content="noindex">
on most pages while this is in place Google will not index these pages. You should change it to<meta name="robots" content="index,follow">
Thanks,
Jeavon
OMG!!! THANKS A LOT MAN. :'(
This is the most stupid mistake that shouldn't been done :(
Unfortunity, promoto.ae only indexed my home page but not the others!
why is that happening? is it because the sitemap.xml showing the page un defined (e.g. promoto.ae/about-us) there's no html or something?
This is the message from Google webmaster: Googlebot couldn't crawl this URL because it points to a non-existent page. Generally, 404s don't harm your site's performance in search, but you can use them to help improve the user experience. More info.
Another note: Usually when you copy a text from the home page and past it into Google, the links if that text should appear. but if i copy text from inside promoto.ae home page, google won't results! so basically non of the pages are indexing!
This is a great thread and it got me a working XML sitemap. I would like to enhance it further to include the lastmod property. In XSLT I would have used the following:
What would be the Razor/MVC equivalent?
Update: I added the following to your script:
This outputs the date as: 7/31/2015 7:41:52 AM. But it needs to be in this format: 2014-12-01T09:31:24+00:00
Update #2: this seems to be working thou it might not be the best approach:
is working on a reply...