Bureaucratic nonsense – or how cookies are going to end the internet

Today website developers in the EU (not including UK for the time being) have to inform users explicitly that they are about to place a cookie on their machine.  They will then need to inform the user that they need to set another cookie on their machine to remember that they have given permission to set the first cookie on the machine.  What.The.Fuck?

Poor Google Analytics

Google Analytics is going to be most hit.  They have the biggest slice of the tracking pie, so how do they set about tell a visitor they are about to set a cookie on the person’s machine.  Or I take it the law will make the website owner state that Google is going to do this?

Poor people that delete cookies on browser shut down

If you clear the cookies from your browser session when you close it, then every time you visit a website you will be asked all these yes or no questions.

That’s just a bit of a pain in the fucking ass.  Stupid European Law makers sitting on some high seat in Brussels over thinking the internet and how they can control it.  Fuck off and leave us alone.


It will be hard.  If you are a .NET developer you will know that Session variables can use Cookies.  You will need to change that straight away.  You can use the database solutions, but that’s not really easy to do.  Cookieless URLs become nasty to deal with and will really impact site.  Although I suppose if you are using Session cookies you are probably an application and will be exempt from the regulations.

So my solution would be for the some sort of super cookie.  One that is based on a certificate of some variety, like SSL that shows on the browser chrome, so you get warned that a cookie has is about to be set – a red flashing button.  The user would then click it, a message appears “can this site place the cookie [yes/no]”, with javascript/browser functionality pausing until an answer is given.  Am sure the browsers can tell when new cookies are being set.

Or the really simple option is…if you don’t know how to use your browser, to stop all cookies being set by using Private Browsing mode or the security features already built in, then get off the internet.  You should need a licence to be allowed a computer 😀

Rant not over, more will surely appear.

Microsoft.Web.Administration.dll Scripting IIS 7.0 on Vista

This is not a full article on how to script IIS7.0.  It’s about getting to that point on how to do it.  And as per usual the internet was full of incomplete information.  Here’s my complete solution when I faced problems.

Firstly the namespace Microsoft.Web.Administration was not available, nor was it in the .NET of the “Add reference” menu option.  To solve it I had to browse to:


and reference the


in that folder.  The namespace was available, and so I was rocking…straight into another brick wall!  What these other websites again forget to tell you is to set permissions on a specific file that the code I will give in a second, needs to have to be able to run.  So the file is found here:


and you need to give it the ASP.NET/NETWORK SERVICE user in security with READ access.  But guess what!?  Yes that still didn’t solve the issue!  I had to go into IIS7.0, choose the Application Pool I was working with, and change the Identity value to LocalSystem.  So thats:

Open IIS > Expand IIS > Application Pools > [select your application pool] > Advanced Settings > Process Model > Identity = LocalSystem

Job done.  Yes at last!  Woo!  I could then add new Rewrite rules into the web.config without having to manually go into IIS!

The code as promised

using System;
using Microsoft.Web.Administration;

public partial class new_iis : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        using (ServerManager serverManager = new ServerManager())
            Configuration config = serverManager.GetWebConfiguration("HIE");

            ConfigurationSection rulesSection = config.GetSection("system.webServer/rewrite/rules");
            ConfigurationElementCollection rulesCollection = rulesSection.GetCollection();

            ConfigurationElement ruleElement = rulesCollection.CreateElement("rule");
            ruleElement["name"] = @"GoToGoogle2";
            ruleElement["stopProcessing"] = true;

            ConfigurationElement matchElement = ruleElement.GetChildElement("match");
            matchElement["url"] = @"^google$";

            ConfigurationElement conditionsElement = ruleElement.GetChildElement("conditions");
            conditionsElement["logicalGrouping"] = "MatchAll";
            conditionsElement["trackAllCaptures"] = "false";

            ConfigurationElement actionElement = ruleElement.GetChildElement("action");
            actionElement["type"] = @"Redirect";
            actionElement["url"] = @"http://www.google.co.uk";

            rulesCollection.AddAt(0, ruleElement);


But I never wrote the code. I found it at http://forums.iis.net/t/1150481.aspx so I have to massively thank them for showing how easy it is.  And remember you will be able to edit any part of the web.config via this code, or similar code ’cause you will need to edit it to your needs.

ASP.NET __doPostBack is not defined

Wow! What a fucking morning! I came into work today to get something working. That something should have been real easy to do (you don’t need to know what it is, just that it was going to be real easy). I exported a copy of the core code, associated it to my website so that I could run the debugger through it and make my changes. This was going to form the basis of the next version of the core code.  But for some reason when I hit any button I received __doPostBack is not defined error in the javascript error console of Firebug. Continue reading ASP.NET __doPostBack is not defined

Uploadify your large files in .NET

With the increase in memory for servers and the subsequent decrease in price, you’d have thought .net would have had a better way to upload files of a larger persuasion built in.  Nope!

So when I found Uploadify I thought, ooh that’s nice!  And I have to thank William Duffy (again!!) for this find.  It gives you a real nice uploading widget thing without the dreaded postback.  As it uses Adobe Flash to achieve this, it means you can concentrate on other things, like the CSS.  It’s also VERY lightweight, only 30kb for the min’d javascript and the swf file.  Well done lads. Continue reading Uploadify your large files in .NET

Facebook’s Graph API and ASP.net

Am enthralled with the new Facebook API. It’s awesomely simple to use. I mean really simple to use. They have changed the authentication process as well, and fuck me it’s so so much simpler than before.

Previously I integrated Facebook Connect with iMapFlickr, to allow uses to post to their own wall automatically, saying that they had created a new map about cheese and bunny rabbits.  But it was such a pain in the ass to use.  But I did it, although am a little balder for it!!

Facebook – now with added thought

The new Facebook API throws essentially everything they have done out the window, rewriting everything and using oAuth to authenticate a user.  They have even made oAuth simpler, which leads me to think it’s not really the full oAuth specification, but hey it works nicely!

But one thing they forgot to do was let .NET developers in on the secrets.  They released all the libraries and code and examples for other programming languages but .NET is sitting outside of Facebook Towers crying, not being allowed into the party as it has “Microsoft” as part of it’s name.  Fuckers.  I sold me soul to Microsoft a long time ago, so I have spent some time working this out. Continue reading Facebook’s Graph API and ASP.net

File uploader with javascript extension validation

I was recently creating a form that needed to upload an image only to an email handler.  The file would then get emailed to the client.

The way that we have always worked this, is the asp.net fileupload control posted back to the server and checked the fuImage.HasFile and then fuImage.FileName, maybe even using the FileInfo class to let it grab the extension, and check it against a list.

But I realised that is real old school, and with the loveliness of jQuery and regular expressions. Again the internet failed me almost, as there are not really good posts or helpers out there that do this. Everything that appears seems to be out of date, or does something similar but not what am wanting. Well here is a quick script to check the file extensions and inform the user if the file is an image or not:

$(document).ready(function () {

        $("#btnRegister").click(function () {
            // check if the file you are going to upload is an image or not.
            var filePath = $("#fileUpload").val();
            filePath = filePath.replace(/^\s|\s$/g, "");
            if (/\.\w+$/.test(filePath)) {
                var m = filePath.match(/([^\/\\]+)\.(\w+)$/);
                if (m) {
                    if (m[2] == "gif" || m[2] == "jpg" || m[2] == "png" || m[2] == "bmp") {
                        return true;

            alert("Please make sure you upload only pictures.");
            return false;



And that’s it. You can quite easily change the file extensions here to suit your needs, even try and do something fancy with call backs to the server with the file extension so you can read a dynamic list or from a config file or something, how should I know that’s you job fs!!

Google Maps API v3 – Multiple Markers, Multiple Infowindows

Like many of you out there that use Google Maps, when v3.0 of it came out you jumped at the chance to use it!  But I couldn’t get the multiple markers, multiple info windows to work, no matter what I found on Google’s site.

Searching got me to this blog:


And it states this guy is writing a book on this very subject.  So this should have the answer.  Well bollocks it did!  Stop writing your book now matey! Continue reading Google Maps API v3 – Multiple Markers, Multiple Infowindows