1

We are in the process of a website redesign, and we'd like to transition over to MVC. It's a very large website, and our current situation is we have a root project, then we have sub-projects nested inside it for each of our departments. This way each department can be recompiled separately. Using virtual directories in IIS, we are also able to have a single Master Page in the root project, which all the other projects use (all our pages are currently ASPX). The downside to this virtual directory solution is that the root master page is not available to the sub-projects when debugging them. We'd like to switch to MVC, and hopefully MVC can solve this issue.

For the new website, I have created an MVC project that will serve as the root project. I have a shared layout all ready to go, but I'm having a couple of big problems:

  1. I can't figure out a workable way to create nested MVC projects for each department. I have tried a number of different ways, but I always end up with a 403 error. I was able to create Areas within the root project and this worked, but this will not allow us to recompile individual Areas, which is a must, as our site is simply too large.
  2. How to share the layout in the root with all the department projects (even during debugging) without relying on IIS virtual directories. I tried using Razor Generator, but it seems a little too complicated for me, and I could never get anything to work, or even figure out if it is capable of doing what I need.

Any advice would be much appreciated. MVC for .Net seems pretty useless for large sites if there is no way to separate sections into other projects that can be compiled individually.

13
  • This is where asp.net mvc Areas shine. Commented Aug 20, 2014 at 21:14
  • Can you compile Areas individually? Because if not, this won't work for us. Commented Aug 20, 2014 at 21:16
  • Areas abstract routing and project organization based on code responsibilities such as MyApp/Accounting, MyApp/Inventory MyApp/HumanResource each area can be worked on as an individual MVC application and bought together into one application using a shared code base. There is no way to compile an area as it just another abstraction to routing but nothing prevents you from breaking up you libraries to match your conceptual areas. Commented Aug 20, 2014 at 21:23
  • @lrb - I understand Areas, but the fact that they can't be compiled separately is a huge problem. Our site is way too large to have to recompile the entire site for a small change in one of our department Areas. You say "but nothing prevents you from breaking up you libraries to match your conceptual areas" but I don't understand what that means. I've tried creating sub-folders and projects for each department within in the root project, but it doesn't work. It's like MVC won't recognize these sub-directories as valid parts of the site, all I get are 403 errors. Commented Aug 20, 2014 at 21:30
  • @tjc59 - There is such a thing as portable areas, but they have their own issues and really should only be used when you need a modular approach, like a plug-in architecture where you ship components separately. Not a good fit for an enterprise. Commented Aug 20, 2014 at 21:30

2 Answers 2

1

To illustrate how this is done. Here's a snapshot of a test project I just threw together. The 403's you were getting were most likely because IIS is configured to no list the contents of folders, and those virtual directories had nothing in them.

The important thing here is that the Controllers and models are in a separate project. And your views are in your main project. It's much more difficult to try and package the views into your external projects. It can be done, but the thinking these days is that you would create nuget packages to deploy your areas to production (which means you end up with all your views together in production anyways).

This is a good first step for you. If you find this isn't enough, then you can look at other methods. But try to make this work for you first.

The other piece you need to do is change your AreaRegistration (which also stays in your main site, though you could figure out a way via Dependency Injection to make these work in the separate projects)

public override void RegisterArea(AreaRegistrationContext context) 
    {
        context.MapRoute(
            "Test_default",
            "Test/{controller}/{action}/{id}",
            // add controller = "yourcontroller" for default controller for area
            new { controller = "Some", action = "Index", id = UrlParameter.Optional },
            new [] { "YourExternalProjectNamespace.Controllers" } <-- This gets added
        );
    }

enter image description here

Sign up to request clarification or add additional context in comments.

7 Comments

Appreciate the assistance. I tried this but couldn't get it to work, kept getting 404 errors. But the more I look at it, I don't think this is the way we want to go.
We ended up figuring out how to get things working by making completely separate MVC projects nested inside the root MVC project and not using Areas (each project is configured as an application in IIS), the 403 errors were simply an issue with the routing config. And to get the shared layout, I think we are just going to create post-build events to copy down the layout files to all the department projects. I think this is going to be the only way we can get everything we want.
@tjc59 - I promise you, it works exactly as I just showed you. My test project I built in 2 minutes works. You get the 404 errors because you most likely did not add the namespace like I pointed out above in the route registration. Or you did not add the default controller action for the area.
I added the namespaces and the default controller action.
@tjc59 - Well, the test project I shows you works. I don't know what you're doing wrong. Do you have custom routing?
|
0

In our soultion, we have a separate project for the presentation layer (MVC web site) that relies on DLLs compiled in other projects for individual areas (disciplines) and core classes (e.g., core repositories, security classes, domain models).

The areas are designed to use base classes that then reference the core or specific classes defined in the other libraries. We make heavy use of interfaces and generics to boilerplate most of the basic functionality in the presentation layer, and then extend it where necessary.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.