How to Map A Community Server Blog as the Home Page
I decided when I started this Blog I was going to use Community Server as the application. Why not it would be free and it a really well done piece of code. Plus Telligent does make money selling commercial licenses and provides top notch support. The ONLY problem I can say I have really had is the obvious ability to make the Blog the default page on the site. I mean Community Server offer so much, but lets face it many of us use it for just as our Blog or our Forums or maybe just a photo gallery.
I met Scott Watermasysk at the NJ Code camp back in November, and I asked him how to make my blog the default page for the site. He referred me to the SiteURLs.config and said something could be done there, but he could not remember how. I looked through what little documentation is available and found nothing of relevance. So I have just been monitoring the support forums on CommunityServer.org, and even made a request or two for this. Finally I got the answer on how to make one of the sections the default page for the site. This thread actually lead me to a post on Dan Bartels' Blog on how to make the Blog the Default page. Hooray, I have found my answer.
One problem now arose, what about all those well indexed links in the search engines, as well as all the readers that have my feed installed. Everything was broken. How could I fix this problem? As you may recall I do a lot of URL Rewriting using httpModules, in fact I am working on a pretty neat entry on how to combine URL Rewriting and SiteMaps (a little teaser for you). So yesterday morning it hit me and I spent 5 minutes last night, yes 5 minutes creating and installing an httpModule to redirect all those broken links, at least I think all of them. If I have missed any possibilities, then I will get to them ASAP!
Public Class CSPathFixer
Implements System.Web.IHttpModule
Public Sub Dispose() Implements System.Web.IHttpModule.Dispose
End Sub
Public Sub Init(ByVal context As System.Web.HttpApplication) Implements System.Web.IHttpModule.Init
AddHandler context.BeginRequest, AddressOf CheckURL
End Sub
Public Sub CheckURL(ByVal sender As Object, ByVal e As EventArgs)
Dim app As HttpApplication = CType(sender, HttpApplication)
If app.Request.RawUrl.ToLower.Contains("blogs/aspnet_blog/") Then
If app.Request.RawUrl.ToLower.Contains("blogs/aspnet_blog/default.aspx") Then
HttpContext.Current.RewritePath(app.Request.RawUrl.ToLower.Replace("blogs/aspnet_blog/default.aspx", ""))
Else
HttpContext.Current.RewritePath(app.Request.RawUrl.ToLower.Replace("blogs/aspnet_blog/", ""))
End If
End If
End Sub
End Class
So basically I check the page as it is being requested. If it contains the part of the path that was used for the old path to the blog I remove it and rewrite the path. The first miss I noticed was the use of default.aspx, which is a real page at the root of the site and the page I wanted to avoid. So I added another little extra check to resolve that as well.
Finally I had to install it in the site's web.confgi file and I was done!
<add name="CommunityServerPathFixer" type="CommunityServerPathFixer.CSPathFixer, CommunityServerPathFixer" />
I hope this will help more people out!