find a location for property in a new city

Friday, 30 July 2010

Developers' guide to search engine optimisation

Search engine optimisation (SEO) is quite a dark art because it is kept somewhat secret by the guys who write the search algorithms. In fact you can make a career out of SEO but that's not you is it. You're a developer and you just want to know roughly the SEO concerns that you should consider when developing a site. No? Oh... well you should. Here is your guide

Status codes and SEO

If you are a developer worthy of gracing the work place you will be well accustomed with 500's and 404's but I notice a lot of interviewees can't tell me what a 301 is. Understanding how different status codes affect SEO is an important start.
301 Permanent redirect
The URL you requested is wrong and should never be used again. Here is the new one. A user won’t see it but a search engine will make a note and be sure to move all its current indexing and value for the old page to the new one.
302 Temporary redirect
The URL has moved somewhere else for now. Search engines will not re-index their page to this new one so will continue to send people to the old page. Your site then 302's them to the new place. This is used for when it is not usual behaviour (e.g. submit new post and you get redirected to that post). Also if you want to appear like on Google this is the one for you.
404 Not Found
Not cool because Google will thing you are an unreliable joke of a site.
500 Internal server error
Not cool because Google will thing you are an unreliable joke of a site. A sneaky Pete will issue a 503 instead.
503 Service unavailable
Means your server is down for some reason. May be maintenance. May be a crash. Whatever it is Google feels sorry for you and will return later to see if it's back. So make an HttpModule that chews up 500's and returns a HttpStatusCode of 503.

Duplicate content

Google despises you for this. If you had a page here: that just contains a list of your favourite socks for example, that's fine. If you also had the exact same list located at search engines would penalise you for duplicate content. Fair enough really because you are deliberately trying to have more pages about socks on your site by copy and pasting the same page.

But there are more subtle variations that if Google finds will tick you off for duplicating content. The following are variations on that do in fact count as duplicate content (unless the content is entirely different of course):
Actionless querystring
E.g. . Say you were logging the source for analytics and the source had no affect on the content. This URL would be marked as duplicate content to
Mixed casing
E.g. I know IIS is case insensitive but there are web servers that are not so Google counts the different casing as a different page and therefore duplicate content.
Secure pages
E.g. The different protocol makes search engines count this URL as a different one from the original.
What to do?
To resolve all of these things you should look into using canonical URLs. Essentially if you put <link href="" rel="canonical" /> in the <head> section search engines will take that as the URL for the page and attribute any value for pages that include that canonical link to that particular URL.

SEO Friendly URLs

I did believe that friendly URLs are not only user friendly but also good for SEO too. Dan Atkinson pointed out that Google do not add weight to a site based on URL. However, another post from Google suggests that site hierarchies are infact used. (If Google aren't looking at URLs for SEO I wonder why they rewrite all their blog posts...)

Regardless of your leaning I would still recommend that clean URLs are considered even if it is only for the benefit of the user. A URL like will have more chance of being linked to or being the URL of choice to click from some search engine results than Of course you will have to do a database look up based on that string rather than the ID so maybe you may prefer to use instead.

To make cleaner URLs you should look into URL Rewriting or ASP.NET 4's Routing engine.

SEO Friendly content

Basic stuff really, make sure you have filled the <title> with the title of the page. All your headings are within <h1>'s, <h2>'s and <h3>'s etc. Make sure you have a <meta content="Everything about socks" name="description"/> and a <meta content="socks, clothing, accessories" name="keywords"/> can't hurt either.

In ASP.NET 4 you can set easily using Page.MetaDescription and Page.MetaKeywords

Follow britishdev on Twitter

Tuesday, 27 July 2010

The specified value is not an instance of type 'Edm.Int64' Parameter name: value. When inserting an object with Entity Framework

When trying to insert an object into my entity data model (i.e. myObjectContext.SaveChanges()) using Entity Framework 4, I got the most confusing error that said "The specified value is not an instance of type 'Edm.Int64' Parameter name: value".

What made it more confusing was that another repository that uses the same entity data model inserted fine. What made it even more confusing was that if I went back to the page that displays the inserted items they were in fact there no matter how many times I refreshed. What made it even more confusing was that they weren't actually in the database!

Mysterious solution

Beware: you won't leave this blog feeling enlightened. What I did worked but made no sense but fixed it:

Given that there is clearly some sort of caching happening I decided to refresh the Application pool for my application. This cleared out all those phantom items that existed on the page but not in the database. Cool...

Then I tried to insert a new item again for a laugh. It worked! It seemed as though recycling the app pools (AKA giving the server a kick up the arse) suddenly made it start working again.

Step 2: Back away slowly from the code and hope it doesn't happen again.

Update: Concrete solution

The problem was I am using Spring.NET for dependency injection and by default it is set to make the references singletons. So I had to change
<object name="MyRepository" type="MyAssembly.MyNamespace.MyRepository, MyAssembly"/>
<object name="MyRepository" type="MyAssembly.MyNamespace.MyRepository, MyAssembly" singleton="false"/>
and it all now works as expected.

Follow britishdev on Twitter

Wednesday, 21 July 2010

Test your LINQ quickly and easily without recompiling

Tired of writing some LINQ then building, then attaching the debugger, then refreshing the page, then waiting for it to compile then see the results, but they're wrong so you detach the debugger then make changes then build then...

Here's a cool little tool that lets you run LINQ queries against you DB or Entity Framework or... well, quite a lot of things actually. The great thing is that you can skip the cycle of editing building etc. It's pretty much direct.

You can even swap between the result set, Lambda expression, SQL and Intermediary language (for some reason):

Download it here:

Follow britishdev on Twitter

Monday, 19 July 2010

System.Data.Entity not referenced when using Entity Framework

I started getting a compilation error telling with a message telling me "CS0012: The type 'System.Data.Objects.DataClasses.EntityObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Entity, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'". This really confused me since the solution built fine but the error only occurred at run time.

Obviously, it is all about adding a reference to System.Data.Entity to my Web project right? I checked and it is already there. Removed it re-added it. Checked for the correct version but still it doesn't like it! Why?

This came about when I used an existing Models project from a different solution in a brand new MVC 2 web application. So I checked the differences between the working solution and the new solution. Both had the same reference in the Web project so what's wrong?


Finally, I found that I had to add the System.Data.Entity assembly in the web.config too! See line 6 below:
<compilation debug="true" targetFramework="4.0">
    <add assembly="System.Web.Abstractions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Routing, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Data.Entity, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

This miraculously made my page start working as expected again.

Follow britishdev on Twitter

Friday, 2 July 2010

SQL Server 2008 Prevent saving changes that require the table to be re-created

I got this notification when I changed a table's column to NOT NULL and tried to save: "Saving changes not permitted. The changes you have made require the following tables to be dropped and re-created. You have either made changes to a table that can't be re-created or enabled the option Prevent saving changes that require the table to be re-created."

This is because the script generated would contain a DROP TABLE statement. Of course it would have saved everything in a temp table before being dropped and re-created the table so nothing would have actually been lost.

Even still, it is probably a nice little safe guard for those who maybe aren't that used to SQL Server but I am so: how to get round it?


If you are confident that you are a legend with your SQL skills and you just want to be left alone you can disable this warning.

Go Tools » Options...

Go Designers » Table and Database Designers and then uncheck "Prevent saving changes that require table re-creation"

Job done - enjoy at your peril!

Follow britishdev on Twitter