asp.net-mvcasp.net-mvc-3asp.net-mvc-routingreusabilityasp.net-mvc-3-areas

How to reuse Areas, Controllers, Views, Models, Routes in multiple apps or websites


I have a test solution which only has one area called Admin.

I would like to reuse Admin across a number of other web applications.

I have a web application setup in IIS, I have then added a virtual application, /Admin coming from Areas\Admin.

When I navigate to /Admin, I see a directory listing. When I try to hit a controller, /Admin/News. I get a 404 error. It could be that the areas are not registering, even though the code is there in the global.asax. However, I am sure I am going about this all wrong.

Please suggest changes for this situation to work.


Solution

  • Areas cannot be reused the way you think (using virtual directories). They are just an inseparable part of the root web application. They simply embed into the root application routes and cannot function without it. By pointing a virtual directory to your Areas folder you are indicating that this is a separate ASP.NET application but that's far from being the case.

    There are projects like MvcContrib Portable Areas which aim to solve those issues. Worth taking a look. Also if you want to embed some Razor views into an assembly that you could reuse among different ASP.NET MVC 3 applications you may take a look at the following blog post.