Archive

Author Archive

Solution for ASP.NET MVC Routing issue on Godaddy shared hosting

May 13th, 2010 admin 4 comments

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!

Categories: Uncategorized Tags:

ASP.NET MVC Routing on Godaddy shared hosting

May 2nd, 2010 admin No comments

For some time now I’ve been working on an ASP.NET MVC site that I had intended on hosting using my Godaddy account.  Well tonight I decided to test it and discovered that routing doesn’t work as one would expect.  I simply uploaded the MVC template that you get when you create a new MVC project.  On Godaddy you install your sites into virtual directories.  The problem is that the url routing is including the virtual directory in the urls.

Let’s say you have a site named www.awesomesite.com and you’re going to put it into a folder (virtual directory) named /awesomesite/.  The routed urls will look like www.awesomesite.com/awesomesite/About

If I have to I will go to a different provider but I’m hoping I can find an easy solution.  If you know how to solve this please post a response.

Thanks!

Categories: Uncategorized Tags: , , ,

Visual Studio Tip #1 – Find and Replace Dialog Docking

November 9th, 2009 admin No comments

Have you ever been in the middle of a Find and Replace where you’re replacing words one by one and then the Find and Replace dialog jumps a bit and you accidentally hit the ‘Replace All’ button?  There’s an easy way to avoid this happening by docking your Find and Replace dialog with your other dialogs such as the Solution Explorer.

First thing to do is right-click on the title bar of the dialog and change the selection from ‘Floating’ to ‘Dockable’.

Visual Studio Find Dialog

Now just move it to the location where you want it to dock

Find and Replace dialog docking

Find and Replace dialog docking

And now your Find and Replace dialog will stay out of the way

Find and Replace dialog docked

Find and Replace dialog docked

Categories: Uncategorized Tags: