3

I have an MVC 3 app that has some core functionality (most important is autorisation) but mainly serves as a portal to different areas or modules. I want to organize thit to different modules that with minor changes also can be deployed as their own website.

The project consists of a Forum, Blog engine, Messaging between users + 4-5 upcoming modules.

I looked at ScottGu's blog about MVC 2 and found something that seemed perfect:

enter image description here

Depending og what the customer need I want to only give them the exact modules they can use. It is also easier from a maintainence view to be able to work and update referencd assemblies in each project and just do a full update for the customers that have that spesific module on their server.

But in MVC 3 there is no apparent way to use Areas this way, do you know how?

Status I will try to add MVCContrib Portable areas to my existing solution and convert my areas ower and will post back the results. If it works I will mark it as the accepted solution.

cfs
  • 1,304
  • 12
  • 30
  • 1
    Have you had a look at Portable Areas (part of MVCContrib) - http://mvccontrib.codeplex.com/documentation? They would fit what you are looking for – Russ Cam Mar 12 '12 at 14:00
  • @Russ Yes, briefly, but I figured based on ScottGu's post that this was something that was done without another framework. When MVC 4 comes I might develop new modules using that, but the Portable Areas might not support it for all i know, and it's a bit frustrating to be stuck becouse of that. Mayby I'm overly careful and it won't be a problem. – cfs Mar 12 '12 at 14:19
  • Why can't you follow ScottGu's approach in MVC 3? – jrummell Mar 12 '12 at 17:03
  • @jrummell He does not describe how, it seems like the way Areas work in MVC 3 is a bit different. Look at: http://weblogs.asp.net/scottgu/archive/2009/07/31/asp-net-mvc-v2-preview-1-released.aspx – cfs Mar 12 '12 at 17:13
  • I haven't tried it, but it looks like it would work the same in MVC 3. Regardless, the automagic View/Script/Content embedded resource features of MvcContrib Portable Areas look very nice. It allows you to reference only the dll of the area project, without having to copy area Views/Scripts/Content to your main project. – jrummell Mar 12 '12 at 19:09
  • Here's a similar question whose answers also point to MvcContrib - http://stackoverflow.com/questions/2840302/reuse-an-mvc-area-in-multiple-mvc-applications – jrummell Mar 12 '12 at 19:24

2 Answers2

3

MVCContrib has portable areas.

http://mvccontrib.codeplex.com/wikipage?title=Creating%20a%20Portable%20Area&referringTitle=Documentation

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
  • thanks. As asked above, I've had a brief look at it, but was a bit anxious to let this be a so central part of mye app because of updates. But if this is the accnowledged way of solving my problem and there is a lot using it I guess I'm just beeing too sceptical. Should be an inherent part of MVC though, based on Scott Gu's blog it seemed to be the plan at least. – cfs Mar 12 '12 at 14:25
  • One question I don't seem to find the answer for regarding this approch. Is there a problem adding this to an existing solution and migrating two existing areas to Portable Areas? – cfs Mar 12 '12 at 14:41
  • @cfs - the only way to find out is try! – Daniel A. White Mar 12 '12 at 17:04
0

This is possible in MVC3: From: http://bob.archer.net/content/aspnet-mvc3-areas-separate-projects

Right click on the shell project and "Add Area...". Type in the area name. This will create an Areas folder with your area in it. (This is not 100% needed but you do need the "Areas" folder and you can steal the XXXXAreaRegistration class for your application.)

Create a new MVC3 empty project in your solution to match your area. Move the XXXXAreaRegistration.cs file from the shell mvc project to the new project and adjust the namespace as applicable. (Or you can manually create an area registration class, it's a pretty simple class. Just use the Add area template generated one as an example.)

Edit the routes in the AreaRegistration folder as needed.

Delete the folder under the areas folder that the template wizard added.

Modify the web.config of the new project and take out the connection strings and the authentication, membership, profile, rolemanger sections. You will not need to deploy this web.config but the razor intellisense doesn't work without it during dev time.

Delete the global.asax file from the area's project or you will get extra default routes.

Create a virtual directory in the "Areas" folder of the shell project with the name of your area as the alias and point it to your "area" project. You will need to use IIS or IIS Express for this. I use IIS. For IIS Express you can use the appcmd.exe in the IIS Express folder or you can edit the applciationhost.config file.
Adam Tuliper
  • 29,982
  • 4
  • 53
  • 71
  • 1
    Thanks Adam, but this suggests that I have to do spesific configuration on each IIS I deploy to and setting up virtual directories? It's not the biggest issue, but ideally i'd want to avoid that. – cfs Mar 12 '12 at 14:22
  • The url linked to is no longer available. I would suggest changing it to the last known cached copy from [web.archive.org](https://web.archive.org/web/20140411193340/http://bob.archer.net/content/aspnet-mvc3-areas-separate-projects). – Dan Atkinson Jan 09 '17 at 13:09