ASP.NET Google Sitemap
Taking this UrlFormatter class into consideration I have modifiied the GSiteMap.ashx file include a method that will write out all the post URLs.
Heres a link to the original code: ASP.NET Google SitemapModifications
Created the write posts function, seems very simple.
private void WritePosts(PostCollection posts, XmlTextWriter writer)
{
foreach(Post p in posts)
{
writer.WriteStartElement("url");
writer.WriteElementString("loc",
MarkItUp.SingleUserBlog.Web.UrlFormatter.FormatUri(p));
writer.WriteElementString("lastmod",
p.DateModified.ToUniversalTime().ToString("yyyy-MM-ddThh:mm:ss.fffZ"));
writer.WriteEndElement(); // url
}
}The only other modification I made was to make the XML node writer look at the “mainMenu” property. This is so it only writes out the items that are actually displayed on the menu.
string displayOnMainMenu = node["mainMenu"];
if(!string.IsNullOrEmpty(displayOnMainMenu) )
{
if(bool.Parse(displayOnMainMenu))
{ …The bigger picture for UrlFormatter.FormatUri()
After doing this I decided to soup up the FormatUri function to allow it to ‘potentially’ format friendly URLs. So I’ve also added configuration setting to allow me to switch, friendly URLs on and off.public static string EncodeUri(string str)
{
char[] badchars = new char[]
{ '?','!','.',',','@','#','$','%','^','&','*',
'(',')','{','}','[',']','<','>','\'' };
foreach (char c in badchars)
str = str.Replace(c.ToString(), "");
return System.Web.HttpContext.Current.Server.UrlEncode(str);
}
public static string FormatUri(ApplicationDataObject item)
{
if (item is Post) {
if (BlogConfigurationSettings.FriendlyURLs)
{
return string.Format("{0}ViewPost/{1}/{2}.aspx", Globals.UrlStartPath,
item.Id, EncodeUri(item.DisplayName));
}
else
{
return string.Format("{0}Posts/Post.aspx?postId={1}",
Globals.UrlStartPath, item.Id);
}
}Now the EncodeUri function has become even more vital in providing correct links to all the posts in the site. So to welcome the friendly URLs change, I’ve been changing all the repeaters to use this as the hyperlink for the posts instead.
<A href="<%# MarkItUp.SingleUserBlog.Web.UrlFormatter.FormatUri((MarkItUp.SingleUserBlog.Services.Post)Container.DataItem) %>"…</A>
So with a few small modifications, basically I can modify all the post URLs in the entire site, by only changing one function. But for now the BlogConfigurationSettings.FriendlyURLs option will remain false.
Download
Download the GSiteMap.ashx file
No new comments are allowed on this post.

Comments
Brendan
Here's the link to the output file
http://www.kowitz.net/GSiteMap.ashx
????
Generate Google sitemap with .net, that was exactly what I was looking for.
Pailtellaflef
Arthritis Dermamax Drugs http://www.supercheapfags.com/ - buy lunesta It works to restore the chemical imbalance caused by sleep problems. http://www.supercheapfags.com/ - eszopiclone without prescription
Speaskken
Nutmeg As A Drug http://www.walkdiggler.com/ - clopidogrel no prescription With Plavix these side effects can be quite serious such as very low levels of white blood cells, thrombotic thrombocytopenic purpura, hemorrhage, and gastrointestinal upset. plavix medication