基于这个问题,在这里和使用代码发现在这里,我试图加载嵌入资源在一个单独的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结构,如下所示:
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时,它最后没有附加任何View.因此,在VirtualFileProvider
Open方法中,虚拟路径将~/plugin/admin
被传入,而它应该~/plugin/admin/Index.aspx
在我上面的路由中定义.我搞砸了我的路线还是我没想到会发生这种情况?
您必须VirtualPathProvider
在Global.asax
Application_Start
处理程序中注册.
您必须使用特殊路径调用DLL中的视图,如下所示: return View("~/Plugin/YOURDLL.dll/FULLNAME_YOUR_VIEW.aspx");
这是一篇包含可下载代码示例的文章,演示了这一点:
http://www.wynia.org/wordpress/2008/12/aspnet-mvc-plugins/