Friday, June 07, 2013

First major annoyance with GoDaddy shared hosting medium-trust

A while back I changed all my .htm pages to .ASPX ones so that I could take advantage of master-pages in ASP.Net.

On Brinkster I simply wrote a handler for the Application_BeginRequest method in the Global.ASAX page that detected .htm calls and re-wrote the URL with the equivalent .ASPX ending.

On GoDaddy this falls down completely because shared hosting will not permit a full trust configuration and so the Application_BeginRequest is only called after the hosting service has verified the URL so you get the lame GoDaddy 404 page.

I tried reassigning the 404 behaviour to my own page and decode the UrlReferrer but that doesn't work either!

In the end I have had to brute force the whole process by creating a redirect page for every .aspx page and giving it a .htm extension. This is a royal pain-in-the-arse because i now need to maintain 325more .htm files that reduce reliability and increase site update times.

If you're interested in this solution, here is the code I used to automatically generate the files:

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            if (dlg.ShowDialog() == true)
            {
                string p =
                    System.IO.Path.GetDirectoryName(dlg.FileName);
                foreach (string s in Directory.GetFiles(p, "*.aspx"))
                {
                    string np=System.IO.Path.GetFileNameWithoutExtension(s);
                    FileStream fs=File.OpenWrite(p + "\\" + np + ".htm");
                    StreamWriter sw = new StreamWriter(fs);
                    sw.Write(String.Format(@"<html>
<head>
<meta http-equiv=""refresh"" content=""0;url=http://bobpowell.net/{0}.aspx"">
</head>
</html>
", np));
                    sw.Flush();
                    sw.Close();
                    fs.Dispose();
                }
            }

        }

You will obviously need to replace the site url with your own or all your pages will redirect to my site which will be great for my AdSense stats but no good for you..

No comments: