Welcome to Professional ASP.NET - Chris Love's Official Blog Sign in | Join | Help

Chris Love's Official ASP.NET Blog

Chris Love's Helpful tips, tricks and pragmatic development knowledge for the ASP.NET world.
Add to Technorati Favorites


ASP Insider
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!

 



Share this post :
Posted: Thursday, February 15, 2007 6:43 AM

by Chris Love

Comments

Dave Burke said:

blog bits It seemed so far away, didn't it? Community Server 2007 Beta 1 has arrived. We are one step

# February 16, 2007 2:30 AM

TrackBack said:

# February 16, 2007 10:18 AM

Daily News List Blog said:

Chris Love reconfigures his blog to display at the site root and posts the code he used to remap his

# February 18, 2007 8:41 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS