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

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

问题描述

我有一个测试解决方案,只有一个区域称为管理员。

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

我想跨越多个其他Web应用程序中重用联系。

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

我在IIS的web应用程序的设置,我已再增加了一个虚拟应用程序, /管理员地区未来\\管理

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

当我浏览到/管理员,我看到一个目录列表。当我尝试打了一个控制器/管理/新闻。我得到一个404错误。这可能是因为该区域没有注册,即使code是有在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应用只是一个不可分割的组成部分。他们只是嵌入到应用程序根路径,没有它不能正常工作。通过指向一个虚拟目录到领域文件夹,你表示这是一个独立的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.

有像<一个项目href=\"http://lostechies.com/erichexter/2009/11/01/asp-net-mvc-portable-areas-via-mvccontrib/\">MvcContrib便携式领域旨在解决这些问题。值得看一看。此外,如果你要嵌入一些剃刀意见纳入,你可以不同的ASP.NET MVC 3应用程序之间重用的组件,你可以看看的<一个href=\"http://www.chrisvandesteeg.nl/2010/11/22/embedding-$p$p-compiled-razor-views-in-your-dll/\">following博客文章。

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天全站免登陆