Head.SmackOnTable();

Contains Nuts.

Archive for May, 2008

Another way to do user based security

with one comment

This is in response to a post by Anas Ghanem – regarding doing Session checks in Page Loads, and asks for a better way to do things – in my opinion there is.

Instead of doing:

public class AdminSecuredPage : System.Web.UI.Page
{
    public AdminSecuredPage()
    {}
    protected override void OnInit(EventArgs e)
    {
        // if the user is not Admin , redirect to Login Page
        if (Session["AdminUser"] == null)
            Response.Redirect("~/login.aspx");
        // this needed to initialize its base page class
        base.OnInit(e);
    }
}

You really should be doing:

image

But, you can further extend this by inherting from a parent base page, like so:

public class BasePage : System.Web.UI.Page
{
    public void RequireRole (String Role)
    {
        if (!User.IsInRole(Role))
        {
            Response.Redirect("~/Login.aspx");
        }
    }

    public void RequireAdministrator()
    {
        RequireRole("Administrator");
    }
}

And then you do the following in the page:

public partial class _Default : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        RequireRole("Administrator");

        // OR

        RequireAdministrator();
    }
}

I think this is a much more elegant way of doing things, plus you are DRY compatible, since you only have to change one url to redirect to.

Written by Monty

May 8th, 2008 at 1:22 am

Posted in .NET

Tagged with ,

Keyboard Autopsy

without comments

A couple of weeks ago, I was a retard, and made my keyboard drink some pepsi. Realising I was a moron, I ran it under a tap (after unplugging it), but it still was rather funky to type (the R key would do tab, then r…and tab would do 5 tabs in a row before simulating someone pressing the caps lock).

So I decided to decimate it and see what was up.

Heres whats inside a top of the range Microsoft Natural Keyboard:

After cleaning it out with compressed air and making sure the membrane thingy (With all the dots and the lines thing) wasnt stuck to the keyboard base (As it was with the R and tab keys), I put it back together.

After an hour of looking where I missed a screw out, I managed to put it back together, and its working perfectly!

Written by Monty

May 1st, 2008 at 1:28 am

Posted in Misc,Moments

Smoking, its a filthy habit…

without comments

Its even worse when your car is doing it while your pegging it down a dual carriage way at 50mph…

Not sure what happened – I could remember smelling something burning, but I didn’t think much of it (I had both windows down, so could have easily been that) – then I notice my windows start fogging up – that’s not a good sign – and then I see white smoke rising out of the air vent next to the wind screen – that’s an even worse sign.

So I panic, pull myself off the road in a safe manner, and call MINI emergency services – half an hour later, a BMW mechanic in an estate pulls up behind me and asks me questions about the car, then starts sniffing around the engine. After muchos trouble shooting, he works out its a heating radiator leak, and the smoke is the antifreeze burning on hot engine parts – he said that would also explain why the floor mats are wet (never figured that out).

He arranges me to take the car to Cooper Wimbledon to have it serviced, which they promptly sort me out and basically steal my car and run tests on it and violate it in ways I never thought possible.

2 days later, they ring me up and say Its all done! Yay! They had to replace the heater matrix, the radiator, and did a coolant replacement for all the coolant that went burny burn. And they valet’ed my car, and washed it for free!

Its nice and shiny now!

Written by Monty

May 1st, 2008 at 1:07 am

Posted in Bad Humour,Misc