40

this question hereと using code found hereに基づいて、別の DLL プロジェクトに埋め込まれたリソースであるビューを読み込もうとしています。元の質問の作成者は、これを行うことに成功したと言っていますが、 MVC ビュー エンジンがリクエストをインターセプトし、ビューのファイル システムをまだ調べているようです。例外:

Server Error in '/' Application.
The view 'Index' or its master could not be found. The following locations were searched:
~/Views/admin/Index.aspx
~/Views/admin/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/App/Views/admin/Index.aspx
~/App/Views/admin/Index.ascx
~/App/Views/Shared/Index.aspx
~/App/Views/Shared/Index.ascx 

次のように、Rob Connery の /App 構造のようなを使用してCustomViewEngineいます。

public class CustomViewEngine : WebFormViewEngine
    {
         public CustomViewEngine()
         {
             MasterLocationFormats = new[] { 
                "~/App/Views/{1}/{0}.master", 
                "~/App/Views/Shared/{0}.master" 
                };

             ViewLocationFormats = new[] { 
                "~/App/Views/{1}/{0}.aspx", 
                "~/App/Views/{1}/{0}.ascx", 
                "~/App/Views/Shared/{0}.aspx", 
                "~/App/Views/Shared/{0}.ascx" 
                };

             PartialViewLocationFormats = ViewLocationFormats;
         }
    }

ここに私のルートがあります:

    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute("Home", "", new {controller = "Page", action = "Index", id = "Default"});
    routes.MapRoute("Default", "Page/{id}", new { controller = "Page", action = "Index", id = "" });
    routes.MapRoute("Plugins", "plugin/{controller}/{action}", new { controller = "", action = "Index", id = "" });
    routes.MapRoute("Error", "{*url}", new { controller = "Error", action = "ResourceNotFound404" });

AssemblyResourceProviderの場合、パスが開始するかどうかを確認してから~/plugin/、dllファイル名の規則を使用していますplugin.{controller}.dll

助言がありますか?

更新:たとえばルーティングされたリクエストhttp://localhost/plugin/adminが VirtualFileProvider に到達するまでには、最後にビューがアタッチされていません。したがって、の Open メソッドでは、上記のルートで定義されている必要があるときにVirtualFileProvider、 の仮想パスが渡されます。ルートを台無しにしたのでしょうか、それともこれが起こると予想するのは正しいですか?~/plugin/admin~/plugin/admin/Index.aspx

4

2 に答える 2

24
  1. ハンドラVirtualPathProvider内に登録する必要があります。Global.asax Application_Start
  2. 次のような特別なパスを使用して、DLL でビューを呼び出す必要があります。return View("~/Plugin/YOURDLL.dll/FULLNAME_YOUR_VIEW.aspx");

これを示すダウンロード可能なコード サンプルを含む記事を次に示します。

http://www.wynia.org/wordpress/2008/12/aspnet-mvc-plugins/

于 2008-10-26T17:58:22.380 に答える
4

組み込みの WebFormsViewEngine は VirtualPathProviders を使用するため、VPP を記述して登録すれば、ビュー エンジンに変更を加える必要はありません。

于 2008-10-26T15:07:48.153 に答える