Solution for ASP.NET routing on GoDaddy shared hosting
photo © 2009 Caitlin Childs | more info (via: Wylio)I was doing a bit of research to try and find some nuggets of information on URL rewriting, especially with regard to GoDaddy’s shared hosting (I run this website (and others) on GoDaddy). I found this article in Google’s cache but the original site (codebeater.com) has gone away (I presume the domain wasn’t renewed). The article was by CodeBeater’s admin.
I didn’t want it to disappear into the ether as I can certainly see me using it in the future. So I copied it here verbatim, just cleaning up some look-n-feel.
[UPDATE 21-Feb-2011: Jeff from the CodeBeater site has revived his blog and has republished this post there.]
Solution for ASP.NET MVC Routing issue on Godaddy shared hosting
This is actually not an issue related to GoDaddy shared hosting at all but an issue with hosting an ASP.NET MVC site in a virtual directory. When you use the shared hosting provided by GoDaddy you get a root folder and limitless subfolders, each of which can be its own domain, by way of virtual directory. Unfortunately, MVC’s routing engine produces URLs that will include the virtual directory name appended to the domain name.
For example, let’s say you have a domain named http://www.example.com and your folder/virtual directory name is /File. If you take the MVC template project without making any modifications and upload it to your folder and then go to your url everything will look fine. You will notice the ‘Home’ and ‘About’ tabs at the top right of the page. When you click on the ‘About’ tab, since it is routed to the Home controller’s About action, you would rightly expect the URL to be www.example.com/Home/About. What you will see, though, is that the URL generated by the ActionLink method includes the name of the virtual directory. Therefore, the URL will be www.example.com/File/Home/About.
If this problem doesn’t bother you then kudos to you. It bothers me and I was really hoping to find a resolution that involved configuration, rather than writing a bunch of custom code for something I felt should work ‘out of the box’. After posting the question here and scouring various forums I found many others having the same problem but not one solution.
Luckily for me, I have a couple of friends and former coworkers that now work at GoDaddy who jumped on this issue when I posted it to their forums. I want to first say thanks to both of them for taking the time to dive into this and finding a configuration-based solution that works perfectly. You know who you are!
So now for the solution, and I probably should have mentioned this at the beginning but hopefully you’re using IIS7 with the URL rewriting module installed (it is installed by default when you use IIS7 on GoDaddy).
Simply add the following into your web.config’s system.webServer element:
<rewrite> <rules> <rule name="Remove Virtual Directory"> <match url=".*" /> <action type="Rewrite" url="{R:0}" /> </rule> </rules> </rewrite>All this does is “rewrite” the URL with itself. This causes URL Rewrite to add the original URL (the one with no folder name) to a ServerVariable which is used by ASP.NET MVC to generate other URLs.
Again, this only works when you’re using IIS7 with the url rewriting module installed.
Good luck!
Now playing:
Dido - Northern Skies (Remix)
(from Safe Trip Home)




