Archive for July, 2008

Effect of HTTP 403-6 Error on Google

A few days ago I discovered through Google Webmaster Tools that some of my sites were unreachable by Google. In particular Google reported my homepage as unreachable and many of my sub-pages returned the same 403-6 error.

After checking my website both with various browsers and response grabbers located around the world I determined that the problem was definately not with the way I had designed the website or configured the hosting.

The HTTP 403-6 error means that an incoming request has been denied (Forbidden) because the IP address is banned or rejected in some way. Initially I tried to determine if this was because of some response error on my part; this was not the case.

I checked my server logs and could see the same errors showing up on every request that came from the GoogleBot (incidentally all requests were on the same IP). I notified my hosting provider and eventually the problem was rectified and the IP address used by GoogleBot at that point in time was unblocked.

I re-submitted my sitemaps and shortly afterwards the errors started to disappear from Google’s Webmaster Tools portal. I hoped that I had got to the root of the problem in time.

The next day while routinely checking websites I discovered that the homepages had disappeared from Google’s search results. Initially I thought that the sites had dropped on their keyword matches but “site:URL” checks showed the actual pages had been dropped.

It has taken 2-3 days for these pages to reappear in the search results and I am still waiting for some pages to come back in. Personally I found the timing to be very bad as I am trying to build Google’s confidence in my websites.

This all points to one of my main tips for SEO. It doesn’t matter about anything else if Google etc cannot see your website. Choose your hosting company carefully.

AR

Generate XML sitemap for Google

There are many sites that deal with returning a Google sitemap from .NET pages. Most of these need you to adjust the IIS settings (yes this is about Windows hosting).

There are also some that deal with creating a sitemap on-the-fly from the web.sitemap file in your project but here I’ve included the code to return an XML sitemap that conforms to the Sitemap protocol that you can submit to Google without modifying IIS – something that should interest those of you who are on shared hosting.

The ZIP download is available at the bottom of this article.

Basically if you create a blank ASPX page and clear out all the HTML elements from the ASPX page you will just be left with the <% @Page %> definition. Below is an example of the only line that needs to be in the front file (.ASPX).

For your purposes, just add the ContentType=”text/xml” section. It may NOT be necessary once you read through the page-behind code, but I’ve left it in as it doesn’t hurt.

Example:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="XMLSiteMap.aspx.cs" Inherits="XMLSiteMap" ContentType="text/xml" %>

Next you will need to put the GSiteMap.cs file in your App_Code folder.

In the page-behind code, you can then simply call the class and all the work is done for you. The code uses the filesystem (whether it is running locally or on a remote server) to generate the sitemap. It will also return the correct protocol type (http or https) and the port number if not on port 80.

I have used this method before the generate an XML file in the filesystem but since my hosting provider doesn’t allow ASPNET to write to the root directory of the site, returning the sitemap on-the-fly is the only truely automated method for this.

In the page-behind’s On_Load event:

protected void Page_Load(object sender, EventArgs e){GSitemap _siteMap = new GSitemap();_siteMap.ProcessRequestFS(Context);}

This simply passes the current HTTPContext to the sitemapping class allowing it to replace the Response with your pure XML sitemap.

I won’t go into the full code at this point because you can read through it yourself from the download. It’s worth pointing out the following however:

private string[] _Allowed_Extensions = { ".aspx", ".php", ".asp", ".htm", ".html", ".txt", ".doc", ".pdf", ".jpg", ".gif", ".xml" };private string[] _Restricted_Directories = { "App_Data", "App_Code", "admin" };

1. Put any extensions you want to be indexed in the “Allowed Extensions” array.

2. Put any directories you don’t want indexed in the “Restricted Directories” array.

Where the code pulls a list of files from each directory I initially used a file pattern, ie:

"*." + Extention

but found that some files were being indexed twice – this is because of a flaw in the framework that will return .ASPX files when you ask for .ASP files. For this reason I re-worked the code. It’s less efficient this way but it’s guaranteed to work.

The call to “ProcessRequestFS” iteratively goes through each directory adding files to the sitemap. If a directory is blocked by the “Restricted Directories” array then all sub-directories of that Directory are also blocked.

You can see an example of the output of this code by visiting: (not currently available)

On my site you may notice that I have temporary removed the optional tags from the sitemap. They are however created in the version available for download.

In particular, the priority tag is automatically down-graded for each directory further down the path that the script has to look.

There is no real error handling in this version but you can add that as necessary.

I checked with Google and Yahoo! and as far as I can see they have no problem with you adding a sitemap with the .ASPX extension.

The full code can be downloaded here: http://www.aaronreynolds.co.uk/page/Code.aspx

The full code is unavailable at the moment and will be online again soon.

If you have any problems using the code, please let me know.

AR

PHP upgrade to 5.x from 4 on CentOS

One of my customers has recently purchased a VPS for their website.  My Linux VPS is on WebFusion, theirs is on EasySpace.

Now unfortunately EasySpace seem to bugger off at 5pm so I had to rely on Google and hope that some of the Linux boys and girls out there were writing in an intelligible way.

Thankfully for me, I was not let down.

My first source was the AtomiCorp wiki: http://www.atomicorp.com/wiki/index.php/PHP

Then I ran into a little problem with a "dummy" library causing my "yum" to fail.  Similar except here: http://languor.us/error-missing-dependency-glibc-common-2-3-4-2-25-needed-package-glibc-dummy-centos-4

With that removed (on account of it being labelled somethink like xxxxxx-dummy-centos-4) I re-ran the update and succesfully upgraded to PHP 5.2.6.

All seems fine (including Plesk) although I expect the packages in Plesk might be out of synch so I'll need to remember the method in case I have to re-install the VPS anytime soon.

PHP, MySQL and even ASP grrr!

I'm not a PHP developer – never have been. I've had to fix problems in PHP sites before now and hence I've picked up a little knowledge of the language.

I've recently been helping my GF to rebuild something using MySQL and PHP and it makes me glad I moved on to using an IDE for server-side programming. It also makes me glad that I can use MS-SQL.

MySQL (we are talking about one of the web-based interfaces here by the way not the actual database) is pretty lousy-looking and difficult to find the features that you need. I know the database has many powerful features but the particular implementation I was using left a lot to be desired.

It's also been a few years since I used Dreamweaver to do any programming but without it I wouldn't have got far very fast in PHP. I'm sure that PHP is far more powerful than classic ASP – in fact I know it is because I've had to do some classic ASP recently. I don't miss using classic ASP though it has to be said.

When I offered to fax something to a friend recently they declined and said they didn't live in the 80s. Classic ASP, like faxes have their uses in todays world but I don't really wanna use them if I don't have to.

I would have to say that anyone moving into web-site server-side programming should look at both camps (PHP and language.NET) before deciding on their path because to be honest once you are used to using one language or system, you'll probably stick with it until it becomes obselete.

The question is when will ASP become obselete?

Unable to Evaluate Expression – explanation

Today was actually the first time (that I can remember) I have come across the following error message:

“Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack”

Unfortuntely, today also happened to be a very long day following a very long night (working until 5am last night).

So when this error appeared in a fresh page, based 90% on my previous code I was stumped, angry and frustrated.  Thankfully for me the error was simple to rectify, however it is important to note the error has a purpose rather than it being a bug.

This error crops up when terminating the Response to a page either through Response.End, Response.Redirect or Server.Trasnfer

You may not even notice the error 95% of the time that it occurs.

I had the lethal combination of a try-catch block and a Response.Redirect.  I think I’ll explain the significance of the error first and then the simple work-around.

Basically, the Response object is a .NET wrapped set of code that has a certain life-path.  This path is supposed to end with a Response.End (either explicit or implied) that passes execution to the Application_EndRequest method.  When the correct path is not followed, a ThreadAbortException is thrown.

I moved my Response.Redirect out of a try-catch block and appended the optional “terminate execution” parameter of “false” as follows:

Response.Redirect(“going-somewhere.aspx”, false);

This alleviated my problem and I was able to go back to swearing about something else that wasn’t working as expected.

Microsoft’s explanation and fixes are listed here: ThreadAbortException when using Response.Redirect

Using an image submit button in PHP

My colleague was getting frustrated earlier when trying to replicate the effects of a form from one website into a different website.  She was using a HTML input tag set to type=image, as follows:

<input type=”image” src=”images/image-name.gif” alt=”Send Message” value=”Submit” />

Now I don’t get involved in HTML that much anymore so I was curious when she said that although the form was posting back when she clicked on the image, the server-side PHP script wasn’t recognising the postback.  In fact, the page was just re-rendering.  My colleague has used this same simple HTML on numerous occassions before including a GET-based PHP form to another page.

After a trawl around Google we found suggestions from the HTML definition that you should specify the HTML action in the “value” attribute.  This we did as above to no avail.

Now since I am always suspicious of PHP (amongst other technologies) for handling things just that little bit different I looked for any PHP-related posts on the subject.

 Turns out this is actually because IE (from version 6 onwards at least) doesn’t send the value for a HTML input of type=image.  Not like Microsoft to adopt just part of a standard I hear you say with you tongue in your cheek.

Now since the type=image is supposed to return x & y co-ordinates from the browser there is a simple work around.

The server-side code would normally receive the following data from a HTML input tag where type=image:

control_name => value
control_name_x => x co-ord
control_name_y => y co-ord

Since with IE you don’t get the value returned you can simply test for the existence of x or y as follows:

 <?php
if (isset($_POST["control_name_x"]))
{
// form submitted 
}
?>

So there we go, PHP not to blame after all.  What was I thinking?

75 percent of my work is now in PHP

I've had my own business since 2003 but since starting Enjoy Online Ltd in 2007 I've found myself working in PHP most of the time.  There are times when I admire the simplicity of PHP – like when I used to program in classic ASP but to be honest, I count the hours until I can write something in C#.

I know that my knowledge of PHP is limited because I've only been using it since 2006 but I wouldn't use the language out of choice.  In the main, my customers have wanted something in PHP because of some plug-in or server restriction or hosting costs.  I now run have two of my own VPS (one on Windows 2003 and one on Ubuntu) so I have more freedom to push a customer in the .NET direction.  My designer develops in PHP however so to keep my developer busy on larger projects, I have to use PHP.  For smaller projects we can combine the design and development quite nicely with me doing all the development in .NET.

I must admit that .NET has been lagging behind the PHP crowd when it comes to sharing usable plug-ins and scripts.  Quite often although you can get hold of a ready-made control or script it will cost you (or cost you more) when you are using .NET.  When I get the time I will be putting up some of my work that I think would benefit others in the community but in all likelyhood there won't be much PHP script going up because there's already a glut of scripts and posts about pretty much everything you would want to do – or at least most of what I've required as I have been bettering myself.

So the reason for this post?  Basically I am hoping that in 2-3 months I can turn around and say "I do 75% of my work in .NET", or that in 2-3 months it won't be a day that I've come home and cursed other developers for their crazy coding in PHP.

Return top