如何创建ASP.NET MVC区作为一个插件DLL? [英] How to create ASP.NET MVC area as a plugin DLL?

查看:277
本文介绍了如何创建ASP.NET MVC区作为一个插件DLL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我想要的实现,我想ASP.NET MVC的地区单独作为纯单个DLL。


  1. Blog.DLL

  2. Forums.DLL

  3. FAQ.DLL

每个人都单独ASP.NET MVC区,拥有自己的默认CSHTML或ASPX页面。安装,迁移和维护大量的网页包括资源,Java脚本等都是长期来看真正的痛苦。因为大多数的这些几乎不发生变化。

我的最后网站将是这样。

  \\ MvcApplication
   \\ BIN
      \\ MvcApplication.bin
      \\ Blog.dll
      \\ Forums.dll
   \\控制器
      \\ ..
   \\楷模
      \\ ..
   \\浏览
      \\ ..
   \\ Global.asax中
   \\ Web.config文件

不添加任何东西,只是删除Blog.dll,我的应用程序应该支持/博客及其所有页面。如果我想自定义的东西,比我可以添加区,只添加CSHTML页面..

  \\ MvcApplication
   \\ BIN
      \\ MvcApplication.bin
      \\ Blog.dll
      \\ Forums.dll
   \\地区
      \\博客
          \\浏览
              \\共享
                  \\ BlogLayout.cshtml< - 这将覆盖外观
   \\控制器
      \\ ..
   \\楷模
      \\ ..
   \\浏览
      \\ ..
   \\ Global.asax中
   \\ Web.config文件

这将有助于重用ASP.NET区插件,只需在下降bin文件夹中的DLL。然而web.config文件可能需要一些变化,但最有可能的,我们将保存配置数据库中,只有将在web.config中实体框架连接字符串需要的东西值。

我的挑战(问题)


  1. 这可能吗?它看起来确实给我,但会不会有任何反射/权限问题?

  2. 如何包括一个DLL中CSHTML / ASPX看法?大概编译版本?我见过几个在codePLEX基于模板文本视图引擎,但我​​是有点困惑如何实际使用它们。

  3. 以及如何我得到的ViewEngine首先检查是否物理目录文件存在与否,然后看看CSHTML / ASPX作为资源文件DLL本身内?


解决方案

您可以看一看的<一个href=\"http://www.chrisvandesteeg.nl/2010/11/22/embedding-$p$p-compiled-razor-views-in-your-dll/\">following文章,它说明了如何自定义的VirtualPathProvider可能为了找回被嵌入到单独的程序集作为资源剃须刀视图中使用。

Here is what I want to achieve, I want to separate AREAs of ASP.NET MVC as pure single DLL.

  1. Blog.DLL
  2. Forums.DLL
  3. FAQ.DLL

Each of them are individual ASP.NET MVC Area, with its own default CSHTML or ASPX pages. Installing, migrating and maintaining lots of pages including resources, javascripts and so on are real pain for long run. As most of these will hardly change.

My final website will be like this.

\MvcApplication
   \bin
      \MvcApplication.bin
      \Blog.dll
      \Forums.dll
   \Controllers
      \..
   \Models
      \..
   \Views
      \..
   \Global.asax
   \Web.config

Without adding any thing, just dropping Blog.dll, my application should support /blog and all its pages. If I want to customize something, than I can add area, and add only cshtml pages..

\MvcApplication
   \bin
      \MvcApplication.bin
      \Blog.dll
      \Forums.dll
   \Areas
      \Blog
          \Views
              \Shared
                  \BlogLayout.cshtml <-- this will override the look
   \Controllers
      \..
   \Models
      \..
   \Views
      \..
   \Global.asax
   \Web.config

This will help in reusing ASP.NET Area Plugins, by simply dropping the dll in bin folder. However web.config may require some changes, but most likely we will save configure values in database and only thing needed will be "Entity Framework connection string" in web.config.

My challenges (Questions)

  1. Is it possible? It sure looks to me, but will there be any reflection/permission issues?
  2. How do I include cshtml/aspx views within one DLL? Probably compiled versions? I have seen couple of text template based View Engines on codeplex but I am little confused on how to actually use them.
  3. And how do I get ViewEngine to first check if physical directory file exists or not and then look into cshtml/aspx within the dll itself as resource file?

解决方案

You may take a look at the following article which illustrates how a custom VirtualPathProvider could be used in order to retrieve Razor views that are embedded into separate assemblies as resources.

这篇关于如何创建ASP.NET MVC区作为一个插件DLL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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