How to reuse Areas, Controllers, Views, Models, Ro

2019-01-09 16:01发布

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条回答
爷的心禁止访问
2楼-- · 2019-01-09 16:15

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.

查看更多
登录 后发表回答