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