Saturday, October 23, 2004

Addicted To Source

Counter Strike is a phenomenon that has largely passed me by; although I've owned a copy for a while via a Half-Life bundle I bought a while ago, and of course through Steam, it's not something I've ever really got into. Maybe it's because of having an ever increasing family and the attendant lack of time required to play the game and learn the maps, or maybe it was the attitude of the l33t 13 year olds playing the game towards n00bs (like myself) that put me off. Anyway, I decided to buy the Half-Life 2 Silver package via Steam the other day (I already had Half-Life 2 on order via Amazon, but I've decided against the additional wait of hanging around for the postman after the game has officially been released). Intrigued as to how the Source engine would perform on my setup, I decided to fire up Counter Strike: Source. Well, blow me down if it's not a cracking game. The graphics are gorgeous, and the gameplay definitely has that 'just one more go...' feel to it. Oh well, better go; I've got years of terrorist related gameplay to catch up on before Half Life 2 is activated....
 Thursday, October 21, 2004

Six Weeks!

I can hardly believe it myself, but it’s been six weeks since I smoked my last cigarette! My local GP surgery runs a smoking cessation program where you see a community nurse every two weeks, and they issue a prescription for nicotine patches (which, considering the exorbitant price of these products is a serious motivation for turning up!)

 

Anyway, enough back-slapping and on with work…

 Tuesday, October 12, 2004

Adventures In Url Rewriting

A project I'm currently working on for my employer using ASP.NET 1.1 requires a coherent mechanism to maintain a consistent look and feel throughout the entire site. Now, as ASP.NET 2.0 isn't here yet (Master Pages would have been a perfect fit for this project) I decided to use a mechanism based on URL rewriting.

In short, all the main 'page' functionality is contained within User Controls. There is a single .aspx page that loads the required user control and instantiates it for display within the HTML template. Using a regular expression based url rewriter mechanism this templating system is hidden from the end user; for example, a request for:

http://localhost/MyApplication/MyPage.aspx

is mapped under the hood to:

http://localhost/MyApplication/Template.aspx?UserControl=Controls/MyPage.ascx

All well and good - I had the basic URL rewriting mechanism in place in a couple of hours, and the start of a working template mechanism a couple of hours after that. However, then the problems started cropping up.

The first major issue cropped up with postbacks. In short, they didn't work. The reason for this is that the ASP.NET framework fills in the action attribute with a canonicalized path to CurrentExecutionFilePath, which is not what's wanted here.

Easy then - change the action in the template page. Wrong; whichever brain dead idiot designed the System.Web.UI.HtmlControls.HtmlForm class hid the implementation of the action attribute. So, you've got to jump through hoops to change the functionality.

My eventual solution was to subclass the HtmlForm and replace the instance in my template page with my new class, ActionForm. ActionForm overrides the RenderAttributes function, which creates a new HtmlTextWriter, my own subclassed ActionFormHtmlTextWriter. This class in turn overrides WriteAttribute which checks to see what attribute it's writing out - if it's "action", then the value is changed to the originally requested Url. Control is then passed back to the original HtmlTextWriter to write the value out. Anyway, if it gets someone else out of the mire, then great.

public class ActionForm : HtmlForm
{
    protected override void RenderAttributes(HtmlTextWriter writer)
    {
        string action = (string)Context.Items["VirtualUrl"];

        if (action == null)
        base.RenderAttributes(writer);

        using (ActionFormHtmlTextWriter virtualWriter = new ActionFormHtmlTextWriter(writer))
        {
            virtualWriter.ActionUrl = action;
            base.RenderAttributes(virtualWriter);
        }
    }

    private class ActionFormHtmlTextWriter : HtmlTextWriter
    {
        private string actionUrl;

        public ActionFormHtmlTextWriter(HtmlTextWriter writer) : base(writer)
        {
        }

        public ActionFormHtmlTextWriter(HtmlTextWriter writer, string tabString) : base(writer, tabString)
        {
        }

        public string ActionUrl
        {
            get { return actionUrl; }
            set { actionUrl = value; }
        }

        public override void WriteAttribute(string name, string value, bool fEncode)
        {
            if (value != null && String.Compare(name, "action", true) == 0)
                value = ActionUrl;

            HtmlTextWriter writer = (HtmlTextWriter)InnerWriter;
            writer.WriteAttribute(name, value, fEncode);
        }
    }
}


 

 Friday, September 24, 2004

Gig Cancelled

I've just had a call from Drummer Bloke to say that The Swan in Southampton have cancelled the gig we were booked for tonight; not that I can blame them - we've buggered them around a few times over the last year, so I'm not entirely suprised. Still, it's a shame.

 Friday, July 30, 2004

New Bloodbikes Site Live

I've finally got around to updating the Yeovil Freewheelers site using DotNetNuke; I should have done it much earlier, but Real Life™ kept on getting in the way....

Anyway, they're a worthwhile charity that deserve support.