如何在多个应用程序或网站中重用区域、控制器、视图、模型、路由 [英] How to reuse Areas, Controllers, Views, Models, Routes in multiple apps or websites

查看:29
本文介绍了如何在多个应用程序或网站中重用区域、控制器、视图、模型、路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个测试解决方案,其中只有一个区域叫做 Admin.

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

我想在许多其他网络应用程序中重复使用 Admin.

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

我在 IIS 中设置了一个 Web 应用程序,然后我添加了一个虚拟应用程序,/Admin 来自 AreasAdmin.

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

当我导航到/Admin 时,我会看到一个目录列表.当我尝试点击控制器时,/Admin/News.我收到 404 错误.可能是区域没有注册,即使代码在 global.asax 中.但是,我确信我的做法是错误的.

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.

推荐答案

区域不能按照您的想法(使用虚拟目录)重复使用.它们只是根 Web 应用程序不可分割的一部分.它们只是嵌入到根应用程序路由中,没有它就无法运行.通过将虚拟目录指向您的 Areas 文件夹,您表明这是一个单独的 ASP.NET 应用程序,但事实并非如此.

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.

有像 MvcContrib 这样的项目便携式区域旨在解决这些问题.值得一看.此外,如果您想将一些 Razor 视图嵌入到可以在不同 ASP.NET MVC 3 应用程序之间重用的程序集中,您可以查看 以下博文.

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.

这篇关于如何在多个应用程序或网站中重用区域、控制器、视图、模型、路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆