Reputation: 633
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:
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.
Upvotes: 1
Views: 919
Reputation: 93494
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
);
}
Upvotes: 1
Reputation: 8236
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.
Upvotes: 0