# Friday, August 24, 2007

Server Error in '/' Application.

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Source Error:


Line 132:                        metaKey.Name = "keywords";
Line 133:                        metaKey.Content = p.MetaKeywords;
Line 134:                        this.Page.Header.Controls.Add(metaKey);
Line 135:                    }
Line 136:                    if (!String.IsNullOrEmpty(p.MetaDescription))

Source File: a:\xyz\ContentHandler.aspx.cs    Line: 134

Stack Trace:


[HttpException (0x80004005): The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).]
   System.Web.UI.ControlCollection.Add(Control child) +2105903
   ContentHandler.Page_Load(Object sender, EventArgs e) in a:\xyz\ContentHandler.aspx.cs:134
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +47
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061

Version Information: Microsoft .NET Framework Version:2.0.50727.832; ASP.NET Version:2.0.50727.832

Another day, another issue ;)

This had me going around in circles for a while until I realised what it was, if you're getting this error you can bet your bottom dollar that you have <%= %> somewhere in your page's header -furthermore I'd hazard a guess that you've got it in some JavaScript to reference an ASP.Net control on the page- and then you're trying to add a control to the header programmatically (or a custom control from someone like Telerik is trying to). Am I right1?

1 I'm not allowed to ask you to so I won't, but if I was right, then spend that bottom dollar clicking on one of the Google Ads :P

I can't tell you exactly why this occurs but my understanding of it is that ASP.Net can't re-create the header if it has Response.Write somewhere in the header (<%=) -most likely due to when the header is created it's not available (will look into it). No doubt you want to know the fix?

The Fix
The fix is simple, remove the inline code blocks and JavaScript and move it to your code behind i.e.:

string _manageSearch = String.Format( @" 
        function ManageSearch(){{
                var lbl = document.getElementById(""lblFindAGift"");
                var txt = document.getElementById(""{0}"");
                var btn = document.getElementById(""{1}"");

                .Do Something with it..



this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "ManageSearch", _manageSearch, true);

Remember: You need to escape the curly brackets otherwise you will get a "String.Format- Exception of type System.Web.HttpUnhandledException was thrown"

Update: Thanks to Julian Voelcker for sending me this alternative "fix" for the problem, can't say I like it though ;) basically instead of using <%= ... %> you would write the databinding expression of: <%# ... %>

Friday, August 24, 2007 10:49:56 AM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [10]  | 

One of the reasons I'm fanatical about Rackspace as a hosting partner is that if you're unsure about something, you know you're able to ask an expert and get a top-notch response to your quandary.

I was recently speaking with another host who was talking about greylisting their emails -in short this is the process of rejecting the first email from a given email address/server and waiting for it to be (automatically) resent by the server later as unlike genuine email servers, most spam servers do not try to re-send an email if it's rejected by a server. We're not able to greylist our emails so I thought I would check that our spam filter settings were up-to-date.

The guys at Rackspace had a look through our spam filter settings and recommended we disabled the statistical filters as they were somewhat outdated technically and increase our connection checks -more importantly, deleting the email after it fails a number of checks. Historically I've been adverse to deleting emails on the server as there's no way to recover them so I asked how accurate connection checks were and thought I would share their easy-to-understand response about what the connection checks do.


In order to understand the unlikelihood of false positives for this case, you must first understand what each check does.

Verify HELO/EHLO domain.

This will create a test in which the domain passed during the HELO/EHLO is used to perform a DNS query to verify that the domain specified has an A record or an MX record. (All valid domains should have a valid HELO/EHLO domain, only mis-configured and spam mail servers fail this test)

Perform Reverse DNS Lookup for Connecting Server.

This will create a test in which the IP address of the connecting server is used to perform a reverse DNS lookup to determine the domain name. If a domain has a valid PTR record, the message is accepted. (Not all valid domains have a PTR record)

Verify MAIL FROM Address.

This will have the "From" address of the connecting server verified for each message to ensure that the user is a valid user on the mail server. If the user or server does not exist, the message is identified as spam. (This is a definite give-away that the message is a spam message).

We can then set the delete threshold to 4. The "Delete message after X matches" will delete the message after it matches 3 of the above rules and/or black lists. This will almost guarantee that the message is spam. If the message fails all Verification checks, it is spam. If the message fails 2 connection checks and a DNS Blacklist check, it is spam. If an email fails both DNS Blacklist checks, and 1 verification check, it is spam. You are pretty much guaranteed that a message is spam. If you want to make extra sure, you could set the delete threshold to 4 that way it will have to fail all verification checks and one blacklist, or both blacklists and two verification checks.

Thank you,

Roberto M Chapa

Friday, August 24, 2007 5:59:42 AM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Wednesday, August 22, 2007

Stacey bought me a Canon IXUS 950 IS for my birthday which needless to say I was more than chuffed to receive, it's a fantastic camera with enough bells and whistles to make it more than just a happy snappy camera but not too many to make it cumbersome to transport so you can ensure you have it to hand when that un-missable shot is coming.

Problem was, on the weekend it developed a fault -Canon's dreaded E24 error. It's predecessor lasted about 4 years before a rainstorm when it decided to start (understandably) complaining for a while but the IXUS 950 IS hasn't had any (recent)1 abuse so I called Amazon fearing the worst but hoping they would replace it as this would appear to be a software related fault.

1 About a week after I got the camera I did drop it but that was mid July.

I first of all emailed them using their online panel as it was out of it's 30 day no-quibble return period but didn't get a response. A little inpatient I decided to call them yesterday and I spoke to a very helpful representative named "Donncha" who assured me that despite my mishap with dropping it there should be no issues in returning it no offence Donncha but I've heard that one before so I didn't hold my breath. He told me a courier would come and collect the camera tomorrow (today) and a replacement would be with me in 3-4 days.

A little later I received -what I assumed was- a collection email saying Royal Mail would be around at some point, I wasn't expecting what happened next. At approximately 10am our usual Royal Mail parcel guy arrived to collect the camera, then, about 5minutes later, another parcel delivery man arrives and drops off the replacement!

I have to take my hat off to you Amazon in this instance, that's superb customer service!

Wednesday, August 22, 2007 9:53:08 PM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 

Exception of type 'System.Web.HttpUnhandledException' was thrown.
at System.Text.StringBuilder.FormatError()
at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
at System.String.Format(IFormatProvider provider, String format, Object[] args)
Error Line

Just got that message (or at most "Exception of type 'System.Web.HttpUnhandledException' was thrown")? Puzzled? I was the first time I got it, I've been meaning to post about it for quite some time now so seeing as I got it again today I took the hint.

The error is horrifingly obvious when you know about it, in short, you've no doubt got some code that looks like this:

String.Format("<html><head><style type=\"text/css\">body{color: #fff;}</style><body>...");

Can you spot it now? Notice your style declaration is using the curly brackets? Basically String.Format is interpreting that as a placeholder i.e. {0} and is throwing a wobbly.

The solution is simple too, just replace all opening/closing brackets with two i.e:

String.Format("<html><head><style type=\"text/css\">body{{color: #fff;}}</style><body>...");

I hope that helps someone out there :)

P.S. Watch out for methods that use String.Format as they may catch you out in the same way -i.e. Subject of System.Net.Mail.MailMessage

Wednesday, August 22, 2007 9:43:12 PM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [6]  | 
# Sunday, August 19, 2007

We've officially been using Chip and Pin in all stores since around February 2007 in the UK which has made life a lot easier in many ways but ever since it's introduction, I for one have had concerns over the claims that it's safer. I agree that it is (or was) harder to find out someone's pin number but has it made shop assistants more complacent?

Stacey and I have a joint Egg Card -I know, what WAS I thinking ;), anyway, these two cards look identical and even had the same pin number and as a result, we recently got them mixed up. I can't say for sure when it was we got them swapped around but one thing for sure is that it was a good couple of months ago. Ever since, we've both been using the wrong card without being questioned, at a guess, I think this has gone on for around 4 months and I only noticed the other day when I looked down and read the name on the card when I was paying online.

This for me is pretty concerning, ok it's because I know the pin, the shop assistant assumes I'm the card holder and doesn't check the name (which the used to when they were forced to check the signature -if they bothered checking that of course ;)).

I think it's also easier to find out the pin too as people aren't overly cautious about entering in their number, I've even seen an old lady in a wheelchair type her pin in on the terminal which was on the desk while she remained lower down in the wheelchair, allowing anyone within about 10m to read what she was typing in. She then promptly put her card back in to her bag and hung it over the back of her wheelchair -where any unscrupulous person could come along and "borrow" the card. It's not just the elderly however, even the young allow other people to read the pin.

I would be interested to know the statistics in crime reduction, I wonder if they're as high as the government were predicting or whether these predictions failed to include the main weak link in the system -us.

On the whole however, it has made life easier and I like Chip and Pin despite these (human) errors, to an extent I think it has made it harder for the criminal to steal (though before he had to learn the signature) but I think people need to be more cautious.

Sunday, August 19, 2007 10:59:43 AM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Thursday, August 16, 2007

"Charge less and just do it quicker" -or- "Charge less, just spend less time on it"

That's what I got from someone that (infrequently) passes me work when I quoted him on some development yesterday. It sums some clients up though, they think you can do the work required -and- get the results by doing less and as for working faster -you can forget that, do they not think we go as fast as possible so we can move onto the next project sooner?

Made me smile so I thought I'd share :)

Thursday, August 16, 2007 5:57:54 AM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Tuesday, August 14, 2007

 What am I doing messing with OS Commerce I hear you cry? Well one of our SEO clients (Florame Organic Aromatherapy) uses a very hacked version of OS Commerce as it's engine and as dire as it is, if it ain't broke don't fix it.

Today I came across (another) error with one of the modules that was installed -the dreaded "1062 - Duplicate entry" error. After a little digging, it wasn't too hard to diagnose, unlike many people (see: 1062 - Duplicate entry fix) this error was being thrown in the product details page. It turns out that since installing the new Froogle feed, the UPC data wasn't being updated, the fix is for you to either remove it and create the UPC by combining i.e. the product code and model number on the fly or to simply validate the new UPC code field is populated.

Easy :) -I hope I saved you trawling through the OS Commerce forums.

Tuesday, August 14, 2007 11:14:15 AM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [1]  | 
# Wednesday, August 08, 2007

As with my previous post, we upgraded the AJAX framework on the weekend which broke a few things, but one control in particular that broke was our TextChangedTextBox which is based on Pete Kellner's timed postback control. Since updating we were receiving a "'debug' is undefined" error on line 1409 (which was in one of the JavaScript include files).

Having had this issue before I updated the TextChangedBehavior.js but that didn't sort it, I have the latest version of the Futures on the server too so I was lost. Turns out I had an old version of the AJAX Futures DLL within the Bin folder of the project.

So as with my post on the ASP.Net forums before -make sure you update your AJAX Futures when updating your Microsoft AJAX framework!

Wednesday, August 08, 2007 6:20:47 AM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Monday, August 06, 2007

Over the weekend we had to upgrade the server's version of ASP.Net AJAX which went fine until this morning when we started receiving the error "Server cannot modify cookies after HTTP headers have been sent."

Luckily this wasn't bubbled up to the UI but incase other people are getting the error I thought I would share the fix. The error is apparently a known error with ASP.Net AJAX and the RolesManager. To fix the error all you need to do is add the following to your RolesManager web.config node:


The full error message was

Server cannot modify cookies after HTTP headers have been sent.

at System.Web.HttpCookieCollection.Add(HttpCookie cookie)
at System.Web.Security.RoleManagerModule.OnLeave(Object source, EventArgs eventArgs)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Monday, August 06, 2007 1:52:08 PM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Saturday, July 28, 2007

My mum gave me a slightly odd Christmas present this year -a beer making weekend. I like many 20 something relished the opportunity to spend a weekend trying out a multitude of different beers, learning what goes into making one and more importantly how I can concoct my own sweet ale. Why then did I start this post saying it was somewhat of an odd present? Well mainly due to my training and much to Stacey's delight I'm virtually tea-total which means my beer-drinking experience thus far in life has been vastly limited to the odd drop of Kronenberg Blanc or Corona (my two current favorite beverage choices) and I can in no way call myself a beer connoisseur (or indeed want to call myself a beer connoisseur). Always wanting to try new things however I went to the beer making weekend with a clear and open mind.

We arrived at Nether Stowey Brewery after a fairly straight forward journey (god bless in-car sat nav systems -they really do take the pain out of navigating) a touch later than planned which meant the other attendees of the beer making weekend had already had the chance to get acquainted with our teacher for the weekend "Ian". I don't know too much about Ian other than he enjoys beer, works -as and when he likes (or so it would appear)- as a very successful employment lawyer and that he likes good beer (I know I've already mentioned that but he really did like his beer...).

The weekend started with a short lesson in beer making, some of the different techniques/flavours produced and a little background behind beer, for instance, did you know that beer was drunk as the primary drink until fairly recently as water was not safe to drink? Or that pale ale was produced by running water through the already used mulch? It was then given to the children as a much weaker beer? Or how about: Most beer and wine is not vegetarian as they use "finings" to remove the impurities (cloudyness) which are made from Fish Liver...

Followed was a discussion on both which drinks we tended to drink at home and what sort of beer we were all looking to produce. There were 5 of us in our group, obviously we were all going to have different opinions of what we wanted from "our" beer. Before we made our final decision we had the part that I think everyone was looking forward to the most -the beer tasting.

The idea behind the tasting was not to get drunk or simply down a load of different beers, we were taught how to taste (and so appreciate) each beer's qualities. It's amazing how different beers that you would assume were similar taste. The names of different beers was also intriguing. My favourite was the acclaimed "Titanic". Having won numerous awards I thought it was going to be a delightful drink, but lets just say the drink went down as well as the boat...

Ian and his most hospitable wife Lynne also run a B&B (The Old Cider House) so your accommodation over the weekend is in very pleasant surroundings -and the food to an excellent standard, we quickly relaxed. It turns out that Ian not only runs beer making weekends, he also produces a selection of fine ales for the local pubs -some of which go down a storm, others not...

The Saturday was primarily spent mulching the various ingredients in a giant vat before leaving it to simmer for a few hours -during which we were left to our own devices -Sam, Pat and I resorted to wandering the streets and playing Pooh sticks of all things in the village's stream.

We then spent most of Sunday naming our new creation, I really dislike trying to name things, naming my company "The Site Doctor" was hard enough but something that came over time, we had a matter of hours to name the beer and create the label. We went round in circles trying to think of something witty yet meaningful, comical yet serious. In the end we settled on "That" with the slogan "Making Life Taste Bitter" -I can't say it was my first choice but the majority ruled.

It was a good 6 weeks before Nether Stowey Brewery finally sent us the products of our weekend of hard work. Carefully packaged in a large cardboard box were 12 bottles of fine ale. I for one (as I'm sure is true with the rest of the group) was not sure what to expect from them so decided to store them away for a special occasion. When I did finally crack one open, I was pleasantly surprised, I can't say it's something I would choose to buy in a pub but it was certainly more drinkable than I was expecting! I've still got a few bottles remaining so if you are -or were- the recipient of one of my bottles, you were either very much liked by me -or disliked, depending on your outlook ;) Needless to say the "Gaunt Brewery" will remain little more than a dream for now...

If you're interested in learning how to make beer, why not try out Nether Stowey's beer making weekend for yourself? I would think it'd make a good stag do. Check out www.4ale.co.uk for more information.

Saturday, July 28, 2007 1:36:55 PM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  |