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

可紊 提交于 2019-11-26 14:46:55

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/6656843/how-to-reuse-areas-controllers-views-models-routes-in-multiple-apps-or-websi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!