private void AddPage(GoogleSiteMap sitemap, Entities.Page page) { var url = (context.Site.Url + "/" + page.Url).TrimEnd(new[] { '/' }); var properties = page.GetProperties <GoogleSitemapProperties>(); sitemap.Create(url, properties.LastModified, properties.Priority, properties.ChangeFrequency); }
protected void Page_Load(object sender, System.EventArgs e) { Response.ContentType = "text/xml"; Response.ContentEncoding = new System.Text.UTF8Encoding(); Response.Write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); String EntityName = CommonLogic.QueryStringCanBeDangerousContent("EntityName"); AppLogic.CheckForScriptTag(EntityName); int EntityID = CommonLogic.QueryStringUSInt("EntityID"); EntityHelper eHlp = AppLogic.LookupHelper(EntityName, 0); Response.Write("<urlset xmlns=\"" + AppLogic.AppConfig("GoogleSiteMap.Xmlns") + "\">\n"); Response.Write("<url>"); Response.Write("<loc>" + XmlCommon.XmlEncode(AppLogic.GetStoreHTTPLocation(false, false) + SE.MakeEntityLink(EntityName, EntityID, String.Empty)) + "</loc> "); Response.Write("<changefreq>" + AppLogic.AppConfig("GoogleSiteMap.EntityChangeFreq") + "</changefreq> "); Response.Write("<priority>" + AppLogic.AppConfig("GoogleSiteMap.EntityPriority") + "</priority> "); Response.Write("</url>\n"); Response.Write(GoogleSiteMap.GetGoogleEntityProductURLNodes(EntityName, EntityID)); Response.Write("</urlset>"); }
private void BuildSitemap(GoogleSiteMap sitemap, IEnumerable <Entities.Page> pages) { foreach (var page in pages) { AddPage(sitemap, page); if (page.Children.Any()) { BuildSitemap(sitemap, page.Children); } } }
static void Main() { var ns = new XmlSerializerNamespaces(); ns.Add("", "http://www.sitemaps.org/schemas/sitemap/0.9"); ns.Add("news", "http://www.google.com/schemas/sitemap-news/0.9"); var ser = new XmlSerializer(typeof(GoogleSiteMap)); var obj = new GoogleSiteMap { Urls = new List <string> { "abc", "def", "ghi" } }; ser.Serialize(Console.Out, obj, ns); }
public async Task Invoke(HttpContext httpContext) { if (httpContext.Request.Path.Value.Contains("sitemap.xml")) { var pages = pageService.Get().MakeTree(); var sitemap = new GoogleSiteMap(); BuildSitemap(sitemap, pages); httpContext.Response.ContentType = "text/xml"; await httpContext.Response.WriteAsync(sitemap.GetXMLString(), Encoding.UTF8); //return Content(sitemap.GetXMLString(), "text/xml", Encoding.UTF8); return; } await next.Invoke(httpContext); }
protected void Page_Load(object sender, System.EventArgs e) { Response.ContentType = "text/xml"; Response.ContentEncoding = new System.Text.UTF8Encoding(); Response.Write("<?xml version='1.0' encoding='UTF-8'?>\n"); Response.Write("<sitemapindex xmlns='http://www.sitemaps.org/schemas/sitemap/0.9'>\n"); Response.Write("<sitemap>"); Response.Write("<loc>" + AppLogic.GetStoreHTTPLocation(false) + "googletopics.aspx</loc>"); Response.Write("</sitemap>\n"); Response.Write(GoogleSiteMap.GetGoogleEntitySiteMap("category")); Response.Write(GoogleSiteMap.GetGoogleEntitySiteMap("section")); Response.Write(GoogleSiteMap.GetGoogleEntitySiteMap("manufacturer")); Response.Write(GoogleSiteMap.GetGoogleEntitySiteMap("section")); Response.Write(GoogleSiteMap.GetGoogleEntitySiteMap("library")); Response.Write(GoogleSiteMap.GetGoogleEntitySiteMap("genre")); Response.Write(GoogleSiteMap.GetGoogleEntitySiteMap("vector")); Response.Write("</sitemapindex>"); }
static void Main() { var ns = new XmlSerializerNamespaces(); ns.Add("", "http://www.sitemaps.org/schemas/sitemap/0.9"); ns.Add("news", "http://www.google.com/schemas/sitemap-news/0.9"); var ser = new XmlSerializer(typeof(GoogleSiteMap)); var obj = new GoogleSiteMap { Urls = { new SiteUrl { Location = "http://www.example.org/business/article55.html", News = "" }, new SiteUrl { Location = "http://www.example.org/business/page1.html", LastModified = new DateTime(2010, 10, 10), ChangeFrequency = "weekly" } } }; ser.Serialize(Console.Out, obj, ns); }