Sometimes I really don’t understand how the providers manage their services. I recently bought an hosting service from Aruba.it, an italian provider, and I always thought that the only good thing about this provider was that it is quite cheap. But going through its web-site I found a lot of updates so I started to change my mind. Big mistake… Yes it’s true, they updated all and now they support .Net 3.5. The problem is that we’re now really close to the .Net 4.0 release and Microsoft released the 3.5 SP1 quite a time ago. They also released a big news (and a great improvement IMHO) in the web development using the technologies from Redmond: the MVC framework.
So I was a little bit too much hopeful, and as usual in these cases after all I’ll find a “nice” surprise, like this time: Aruba.it supports .Net 3.5 but it looks like it’s not the same for the SP1 and for sure there is no support for the MVC Framework (too much work guys?? so difficult to ADD, not to replace, a couple of f***ing officially released assemblies to the GAC, right???). I also tried to call the customer care, but… nothing changed: they answered me with a two rows e-mail (ok, now I’m quite sure: those guys are super busy or super lazy..) in which they wrote that they don’t support MVC (thanks, I just figured it out by myself).
In any case, all this long introduction to say what? Not more than a couple of things: one, IMHO, I think the world is full of some providers better than this, and the other one is that I tried to take advantage of the architecture of .Net and I was able to let Asp.Net MVC run on an Asp.Net 2.0 web-site! COOL!!!
Ok. So.. first let’s try to figure out how we can do it: all the new .Net releases are still compatible and based on the 2.0 Fx… something like a little onion. 😉 This little thought was also endorsed by my little search on the Internet (or if you prefer you can say that I Bing(ed) or Google(d) a bit around) and I found this good article on the MSDN library: How to: Deploy an ASP.NET MVC Application, in which they confirmed what I was thinking about and they also list, in a bit more official way , the assemblies that we will need to accomplish our “porting” (not all actually, but this will see it better after).
Now we need to do something for real, so let’s open Visual Studio and go..
First of all we need to open the new project dialog box, select the Web project types and then the “ASP.Net MVC Web Application”. We follow all the instruction from the wizard, creating also the Test project, and then our new ASP.Net MVC web site will be ready to run, but not to deploy remotely.
Running the project all the things are working.. on our machine (“but it works on my machine!”).
The first step to do now is to convert all our stuff to the old .Net version: so we have to open the Properties of the project and we can simply do it double clicking the Properties section just under the project folder in the Solution Explorer, then we have to select the right version (2.0) in the Target Framework, just like in the picture.
This is something that Visual Studio won’t like it, but we have to not care so much about it, at least this time, so we answer Yes to both of the questions that it will show up, also to the last one that looks a little bit “dangerous” and now our project it’s ready to be deployed as a .Net 2.0 Web Application but it’s not yet a .Net 2.0 ASP.Net MVC Application. We need some other steps to do that.
Now there are a couple of steps to do to finally let our MVC Application run under .Net 2.0.
We have to manually add the MVC assemblies to our project and to do this we can actually choice between two ways: the easiest way is to locate the 3 MVC assemblies (System.Web.MVC, System.Web.Routing and System.Web.Abstraction) and set that we want to copy them locally (setting the Copy Local property to true in the assembly reference properties) so after when we’ll deploy the project Visual Studio will automatically add them to our deployed application “bin” folder, or the other way is to delete the reference of those 3 assemblies from the project then physically copy them to the bin folder from the GAC folder (that is in C:WindowsMicrosoft.NetassemblyGAC_MSIL… and we have to access this folder with a user with administrator level) and then from Visual Studio directly reference these assembly (Add Reference –> Browse). We didn’t finish yet our job with the assemblies: we’re still missing one that we need to add to our project, cause some parts of the MVC Fx actually refer to it, that is the System.Core.DLL (also this is to locate inside our GAC folder). So this is the list of all the assemblies that we need to manually reference inside our project:
Ok we almost finished. If we’ll try, our project should be able to compile but it won’t work properly. To completely accomplish our task we need also to make some code modification:
- in the Global.asax file, in the root folder of our web application, we need to modify the routing rules simply adding an “.aspx” every time we refer to a particular Controller and make a particular rule for the Home page like in the following snippet
- in all the .aspx files (and the Site,Master too) we have to change all the Html.ActionLink and Html.RenderPartial methods to something like this:
<% System.Web.Mvc.Html.RenderPartialExtensions.RenderPartial(this.Html, "LogOnUserControl"); %>...<li><%= System.Web.Mvc.Html.LinkExtensions.ActionLink(this.Html, "Home", "Index", "Home")%></li><li><%= System.Web.Mvc.Html.LinkExtensions.ActionLink(this.Html, "About", "About", "Home")%></li>
And after this last steps, rebuilding all the project we will be able to host our ASP.Net MVC application in our Asp.Net 2.0 web space, also if you made a so poor choice about the hosting provider like I did!