基于这个问题here并使用代码发现here,我正在try 加载视图,这些视图是一个单独的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
我使用的是CustomViewEngine
,比如Rob Connery的/App structure one,如下所示:
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
有什么建议吗?
UPDATE:当路由的http://localhost/plugin/admin
请求到达VirtualFileProvider时,它的末尾没有附加任何视图.因此,在VirtualFileProvider
的Open方法中,~/plugin/admin
的虚拟路径被传入,而实际上它应该是~/plugin/admin/Index.aspx
,正如我在上面的路由中定义的那样.我是不是搞砸了我的路由,或者我预料到这会发生是对的吗?