Owen pointed me to a snippet that fixes wordpress permalinks on IIS. Although the solution is not very clean, it works very well. What you need to do is set a 404 error page from your website control panel and point it to a *.php file with the following code.

<?php
$qs = $_SERVER['QUERY_STRING'];
$_SERVER['REQUEST_URI'] = substr($qs, strpos($qs, ‘:80′)+3);
$_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'];
include(’index.php’);
?>

When a user visits a permalink url, IIS will throw a 404 exception which will be handled by the above code. The logic is dead simple: The REQUEST_URL and PATH_INFO servervariables are overridden by the permalink path. In this case it is : /2008/04/30/permalinks-on-iis-wordpress/.

The last line simply loads index.php and opens the correct page because PATH_INFO and REQUEST_URL are correctly set.

The other day I was checking my hotmail account to curiously check how many spam emails have made it to my inbox. To my surprise I found out a “hidden feature” on hotmail to forward mail to another email account. This is what I needed. Well I wouldn’t have to bother checking this account again. After all, I’m having trouble remembering the password and it would take some brain cell crunching to figure that out. Anyways, if you’re interested (probably you’re not), the feature is under options -> “forward mail to another account”.

A light bulb switched on in my head! I was thinking about forwarding mail to my gmail account however I got a little nice error message saying: You’re only able to forward mail to a custom domain or an e-mail address that ends in hotmail.com, msn.com, or live.com. Please try again. This sort of message simply implies that Microsoft is more than aware that their competitors offer a better service.. Why not try and beat them? Ok, so after reading the message I thought why not forward the hotmail account to a custom domain which in turn redirects to gmail anyway? I was so wrong! When I typed in my email @ custom domain I got the same error message again. “Microsoft”, I’m honestly dumbfounded! Why would you want to tell me that your competition is better and then offer me a service that doesn’t work? For god’s sake, why would I want to forward mail to another hotmail, msn or live account? Apparently this is the only forwarding that works.

Screenshot below.

It’s been quite a while since I last posted on here. Anyway, here is a class that encrypts data and encodes it using base64 for use in querystrings. The decrypt function does the opposite thing.. it first decodes and then decryptes the string.

public class Encryption64
{
private byte[] key = {};
private byte[] IV = {18, 52, 86, 120, 144, 171, 205, 239};

public string Decrypt(string stringToDecrypt, string sEncryptionKey)
{
byte[] inputByteArray = new byte[stringToDecrypt.Length + 1];
try {
key = System.Text.Encoding.UTF8.GetBytes(sEncryptionKey.Substring(0, 8));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
inputByteArray = Convert.FromBase64String(stringToDecrypt);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(key, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
System.Text.Encoding encoding = System.Text.Encoding.UTF8;
return encoding.GetString(ms.ToArray());
}
catch (Exception e) {
return e.Message;
}
}

public string Encrypt(string stringToEncrypt, string sEncryptionKey)
{
try {
key = System.Text.Encoding.UTF8.GetBytes(sEncryptionKey.Substring(0, 8));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = Encoding.UTF8.GetBytes(stringToEncrypt);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(key, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
return Convert.ToBase64String(ms.ToArray());
}
catch (Exception e) {
return e.Message;
}
}
}

This is a followup post to a previous post on which I have explained that I bought 2 usb pendrives of 8gb each from ebay which simply didn’t work. I have now discovered that these products were scam. The pendrives were actually 2Gb in size and were manipulated by software to make them look as if they were 8Gb. This explains why files were copied fast after the 2Gb memory was full. Do not ever buy stuff off ebay from Far East sellers cos  most of them are fraudulent sellers. The following image shows how windows sees the pendrive as 8gb.  After formatting the pendrive using Iformat, the size drops down to 2Gb.

This is the reply I got from the seller. It is funny - The seller is claiming that unconfirmed files (whatever they are) have attacked the device (possibly by aliens)! WOW.. that’s trustworthy!

Dear Sir/Madam,

Sorry to hear that. Please try to make sure that the files format is formal.

Note: sometimes some unconfirmed files will attack the device,
it may even the the memo corrupted. so please be care of this problem.

Regards,
Digittrend.

fakeusb.gif

You might think that paying a tenner (£10) is cheap for an 8Gb samsung memory pen drive. Of course it is - but guess what… I ordered 2 of them from ebay and they were both defective. DO NOT ever buy cheap memory from ebay cos it doesn’t work.

To test them out, I just put an avi file and tried to play it. All I got was a blank corrupted video. On the item description it says 10 years of memory retention but it would have been much better if they said 10 seconds memory retention :).

Do not get blinded by the cheap price cos in the end it turns out to be more expensive!

UPDATE:

Here is the reply I got from the seller:

Dear Sir/Madam,

Sorry to hear that. Please try to make sure that the files format is formal.

Note: sometimes some unconfirmed files will attack the device,
it may even the the memo corrupted. so please be care of this problem.

Now that’s a mouthful. What the heck is a formal file?
Attack the device? Are these some kind of alien files? That is funny!

I’m sure you agree with me that errors which are hard replicate are difficult to resolve until you figure out what is going on. This was one of those worth blogging about it.

The problem:
To cut a long story short, some time ago I set up a website to receive any errors that occur on the live site by email. After passing some rigorous testing procedures I was surprised that I was receiving many Unhandled HTTP Exceptions by email with Error Message being : Exception of type ‘System.Web.HttpUnhandledException’ was thrown. I started scratching my head because on the development environment the site was working well and I double checked configuration settings and ensured that they were fine. Anyways, this error wasn’t helpful so I decided to include the stacktrace of the inner exception.

The error message of the inner exception was something along these lines: Exception of typeSystem.Web.HttpUnhandledException’ was thrown. Cannot use a leading .. to exit above the top directory.

I figured out from the User-Agent http header that this exception was being thrown when a google or yahoo slurp bot tried to crawl the site. I confirmed this by testing pages using a googlebot spoofer and boom, I was getting an unhandled http exception.

The solution:
Believe it or not, the jist of the problem was Url Rewriting. Instead of improving search engine ranking, Url Rewriting was preventing crawlers from indexing any pages. ASP.NET 2.0 uses an adaptive rendering pattern to render html depending on user agents. When a bot visits the site, System.Web.UI.Html32TextWriter gets used to render the html and apparently this throws an exception when System.Web.Util.UrlPath.ReduceVirtualPath() gets called internally by the .net framework when using Url Rewriting. To workaround this problem I set up .browser files for major search engine bots like googlebot and Yahoo! Slurp to force them to use System.Web.UI.HtmlTextWriter. Alternatively, you can have a base page override the CreateHtmlTextWriter as following:

protected override HtmlTextWriter CreateHtmlTextWriter(TextWriter tw)
{
return new XhtmlTextWriter(base.CreateHtmlTextWriter(tw));
}

Thankfully this has solved the mystery exceptions I was receiving by email! The moral of the story is to always send an email when an unhandled exception gets thrown on the live environment. Had I not did this, bots would have never indexed the site.

Have you ever noticed that the loading time of a webpage that references http://www.google-analytics.com/urchin.js slows down drastically?

The solution is very simple. Host the urchin.js file on your server and update your local file automatically once daily.

All you need to do is set up a timer in the Application_Start Event and set it’s Elapsed property to 3500000 (i.e, 58 mins). Then, in the Elapsed event handler just write the following code that updates your local urchin.js file daily at Noon.

How easier can that be?

if (DateTime.Now.ToUniversalTime().Hour == 12)
{
try
{
//download google analytics
System.Net.WebClient client = new System.Net.WebClient();
client.DownloadFile(”http://www.google-analytics.com/urchin.js”, WebConfigurationManager.AppSettings["path"].ToString());
}
catch
{
//do nothing
}

}

7th Jan, 2008

Bill Gates last day

If you want to see Bill Gates singing, playing Guitar hero and driving his ford focus, then you should have a look at this video. Believe me, this is hilarious!

28th Dec, 2007

SSL and google analytics

If you have ever installed google analytics on a secure page you should have noticed a certificate warning which indicates that the page contains both secure and unsecure content. This is caused by the google analytics reference to http://www.google-analytics.com/urchin.js. Luckily, google have thought about serving the javascript file over a secure connection. All you need to do is just use this url for the secure javascript file:

https://ssl.google-analytics.com/urchin.js

I’d like to wish all my blog readers a happy Christmas and a new year full of health and happiness. I have managed to achieve some important goals in 2007 and am eager to set newer ones for 2008 - the only difference is that they are tougher to achieve :)

Although this blog has only been online for a couple of months, I was very impressed with what the blogosphere has to offer.

Once more, I wish you all the best for 2008.

Categories