CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Brendan Tompkins [MVP]

Blog First. Ask Questions Later.

June 2006 - Posts

  • Create Unlimited Subdomains with HTTP Modules

    I recently took the hundred or so top search words for CodeBetter.Com and created an “Explore CodeBetter” control with links to pages about those search words.  I wanted the links to be to a subdomain with the keyword as the first label of the subdomain.  So, agile would link to agile.codebetter.com, which internally would be forwarded to a handler that hooks into Community Server’s search engine and presents a list of pages containing the word agile.  As implemented, this control currently looks like this:

    Setting up DNS

    If your DNS supports wildcard syntax, you’ll be able to do this.   Basically you just want to forward all requests to *.yourdomain.com to yourdomain.com.  If your ISP’s dns doesn’t support the wildcard syntax, you could handle your own DNS on your server.

    Setting up IIS

    If you use host headers and you’ve got a bunch of different sites configured, you’ll need to add a blank host header, so that any requests for subdomains not listed  get forwarded to the proper website.   If you want to set this up for multiple websites per server, I’m not sure how to do this, perhaps someone out there knows how.  Basically the hostheader configuration won’t accept *.yourdomain.com, so I’m not sure how to set this up, except to have all un-configured domains going to one website using the blank hostheader technique.

    Creating the HTTP Module

    Next, you’ll need to intercept the request, inspect the requested URL and forward requests appropriately.  A good way to do this is by creating an IHttpModule and plugging it into the pipeline.  For forwarding, all you’ll need to do is handle the OnBeginRequest event, and then use Server.Transfer to forward the request.  The nice side-effect of this is that the URL in the browser doesn’t change when using Server.Transfer (as opposed to Response.Redirect), leaving your nice clean URL in the browser.  Here’s the code for my handler.  I also do some checking to make sure that the homepage (default.aspx) was requested, because I don’t want to do this on sub-page requests. 

       public class SubdomainModule : IHttpModule

        {

            public void Init(HttpApplication app)

            {

                // register for pipeline events

                app.BeginRequest += new EventHandler(this.OnBeginRequest);

            }

     

            public void Dispose() {}

     

            public void OnBeginRequest(object o, EventArgs args)

            {

     

                // get access to app and context

                HttpApplication app = (HttpApplication)o;

                HttpContext ctx = app.Context;

     

                if (!(app.Context.Request.Url.Host.StartsWith("codebetter") || app.Context.Request.Url.Host.StartsWith("www")))

                {

                    if (ctx.Request.Path.ToUpper() == "/DEFAULT.ASPX")

                    {

                        string[] domainParts = app.Context.Request.Url.Host.Split(".".ToCharArray());

                        if (domainParts.Length > 2)

                            ctx.Server.Transfer("/explore/explore.aspx?q=" + domainParts[0]);

                    }

                }

            }

        }

    Registering the Module in the pipeline

    This is simple, you can just add the following to your web.config file:

    <httpModules>
       <add name="SubdomainModule" type="Tompkins.Cs.Subdomains.SubdomainModule, Tompkins.Cs.SubdomainHandler" />
    </httpModules>

    That’s it!  Any requests will be forwarded.  You can now simply request any subdomain on codebetter, like http://monkeys.codebetter.com or http://baseball.codebetter.com.  Need advice on relationships or read that funny post about my ex-girlfriend finding my blog?  Just type http://girlfriend.codebetter.com.  Heck, you could even use us as a help system!  If you need to know about ADO, just type http://ado.codebetter.com. Good luck!

    -Brendan 

     

  • Help Spread the Word - Devlicio.us

    For a while now, I’ve been working on designing and planning a new blogging site called devlicio.us.   Like CodeBetter.Com, it’s going to be a small, focused blogging site with only enough quality content that you should be read the main feed in one sitting.  I’m very much a believer in small,  focused feeds, and while I don’t necessarily think that the world needs another new blogging site, I think we could stand to see a few more of these. 

    I’ve already lined up some great blogs, so stay tuned!  If you think you’d like to have a blog with us, and be a part of something sure to be a hit, send me an email at brendan.tompkins@gmail.com.

    Thanks!

    Brendan

  • The Java Posse on Agile

    Recently, I've started to listen to the JavaPosse podcasts, over at JavaPosse.Com.  I find it really interesting to hear about the issues that the Java world is facing, especially since many of them are essentially the same as in the .NET world.    Actually, I think the differences between the two worlds are getting smaller and smaller as we adopt more of the Java Camp's tools and methodologies.  Anyhow, it's a good podcast, I recommend it.

    This week, they're talking a bit about the Cedric Beust rant post on Agile.  The Java Posse guys have a very refreshing common sense discussion of Agile.  I'm not sure where we're going to end up after the current zeitgeist of Agile bashing, but as a proponent of agile, I'm not too worried.

    I'm actually reminded of a similar paradigm shift that happened in the world of psychology in the last 50 years or so.  Around the middle of the 20th century most of psychology was focused on behaviorism.  There were zealots who thought every aspect of being alive could be explained and manipulated by some very simple, proven principles of behavior.  Predictably, there was a huge backlash against behaviorism where many psychologists claimed that human behavior was much more complex – the Cognitive revolution.  So who was right?  Well, it depends.  When you absolutely have to change behavior, when there’s money or lives on the line, the theory that get adopted and applied is behaviorism.  Why?  Because it works.

    So, why am I not worried about the future or Agile?  I think a similar thing is going to happen in the future with software development.  When it really matters, when there’s lots of money or lives on the line,  when maintainable software has to be done right in a short amount of time with few errors, Agile principles are going to win out.

    -Brendan

    Technorati Tags: ,

More Posts

Our Sponsors

Free Tech Publications