- Posted by miketeye on May 3, 2010
Share on FacebookVevocart has a free version which enables a merchant to setup a simple online shop with very little initial capital. However, there are a lot of features on vevocart which are only available with the premium version. One such feature is Search Engine Optimisation or SEO for short.
I needed to provide a dynamically generated google sitemap compatible xml feed for use with the google webmaster tools, so I coded one up in VB.Net. If you need it you may download it by clicking the link below.
using System;
using System.Web;
using System.Xml;
using System.Text;
using System.Configuration;
using System.Data.OleDb;
public class sitemapclass : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
String changefrequency = "weekly"; // always, hourly, daily, weekly, monthly, yearly, never
using (System.IO.TextWriter textWriter=new System.IO.StreamWriter(context.Response.OutputStream,System.Text.Encoding.UTF8)) {
XmlTextWriter writer = new XmlTextWriter(textWriter);
writer.Formatting = Formatting.Indented;
writer.WriteStartDocument();
writer.WriteStartElement("urlset");
writer.WriteAttributeString("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");
// Add Domain
writer.WriteStartElement("url");
writer.WriteElementString("loc", "http://" + context.Request.ServerVariables["SERVER_NAME"] + context.Request.ApplicationPath.TrimEnd('/'));
writer.WriteElementString("changefreq", changefrequency);
writer.WriteElementString("lastmod", DateTime.Now.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
writer.WriteEndElement();
// Add Home Page
writer.WriteStartElement("url");
writer.WriteElementString("loc", "http://" + context.Request.ServerVariables["SERVER_NAME"] + context.Request.ApplicationPath.TrimEnd('/') + "/Default.aspx");
writer.WriteElementString("changefreq", changefrequency);
writer.WriteElementString("lastmod", DateTime.Now.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
writer.WriteEndElement();
// About Us Page
writer.WriteStartElement("url");
writer.WriteElementString("loc", "http://" + context.Request.ServerVariables["SERVER_NAME"] + context.Request.ApplicationPath.TrimEnd('/') + "/AboutUs.aspx");
writer.WriteElementString("changefreq", changefrequency);
writer.WriteElementString("lastmod", DateTime.Now.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
writer.WriteEndElement();
// Contact Us Page
writer.WriteStartElement("url");
writer.WriteElementString("loc", "http://" + context.Request.ServerVariables["SERVER_NAME"] + context.Request.ApplicationPath.TrimEnd('/') + "/ContactUs.aspx");
writer.WriteElementString("changefreq", changefrequency);
writer.WriteElementString("lastmod", DateTime.Now.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
writer.WriteEndElement();
// Policy Page
writer.WriteStartElement("url");
writer.WriteElementString("loc", "http://" + context.Request.ServerVariables["SERVER_NAME"] + context.Request.ApplicationPath.TrimEnd('/') + "/Policy.aspx");
writer.WriteElementString("changefreq", changefrequency);
writer.WriteElementString("lastmod", DateTime.Now.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
writer.WriteEndElement();
using (OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + context.Server.MapPath(ConfigurationManager.ConnectionStrings["MainConnection"].ConnectionString)))
{
using (OleDbCommand productsCommand = new OleDbCommand("SELECT productID, UrlName from Product", conn))
{
conn.Open();
OleDbDataReader productReader = productsCommand.ExecuteReader();
while (productReader.Read())
{
// products
int productid = int.Parse(productReader["productID"].ToString());
string urlname = productReader["UrlName"].ToString();
writer.WriteStartElement("url");
writer.WriteElementString("loc", "http://" + context.Request.ServerVariables["SERVER_NAME"] + context.Request.ApplicationPath.TrimEnd('/') + Vevo.UrlManager.GetProductUrl( productid, urlname ).Replace(@"~",@""));
writer.WriteElementString("changefreq", changefrequency);
writer.WriteElementString("lastmod", DateTime.Now.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
writer.WriteEndElement();
}
}
using (OleDbCommand categoriesCommand = new OleDbCommand("SELECT CategoryID,UrlName from Category", conn))
{
OleDbDataReader categoryReader = categoriesCommand.ExecuteReader();
while (categoryReader.Read())
{
// categories
int categoryid = int.Parse(categoryReader["CategoryID"].ToString());
string urlname = categoryReader["UrlName"].ToString();
writer.WriteStartElement("url");
writer.WriteElementString("loc", "http://" + context.Request.ServerVariables["SERVER_NAME"] + context.Request.ApplicationPath.TrimEnd('/') + Vevo.UrlManager.GetCategoryUrl( categoryid, urlname ).Replace(@"~",@""));
writer.WriteElementString("changefreq", changefrequency);
writer.WriteElementString("lastmod", DateTime.Now.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
writer.WriteEndElement();
}
}
}
writer.WriteEndDocument();
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
Please post any bugs or feedbacks. As usual the download is without any warranty what so ever.
HTH
sitemap.ashx (5.37 kb)