Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing VirtualPathProvider to load ASP.NET MVC views from DLLs
    text
    copied!<p>Based on this question <a href="https://stackoverflow.com/questions/19746/views-in-seperate-assemblies-in-aspnet-mvc">here</a> and using code found <a href="http://www.codeproject.com/KB/aspnet/ASP2UserControlLibrary.aspx" rel="nofollow noreferrer">here</a> I'm trying to load views that are embedded resources in a separate DLL project, and the original question's author says he has had success doing this - but I can't get it to work as it seems the MVC view engine is intercepting the request and still looking at the file system for the view. Exception:</p> <pre><code>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 </code></pre> <p>I am using a <code>CustomViewEngine</code>, like Rob Connery's /App structure one as follows:</p> <pre><code>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; } } </code></pre> <p>Here are my routes:</p> <pre><code> 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" }); </code></pre> <p>In my <a href="http://www.codeproject.com/KB/aspnet/ASP2UserControlLibrary.aspx" rel="nofollow noreferrer"><code>AssemblyResourceProvider</code></a> I'm checking to see if the path starts <code>~/plugin/</code> and then using the dll filename convention <code>plugin.{controller}.dll</code></p> <p>Any suggestions?</p> <p><strong>UPDATE:</strong> By the time the routed request for say <code>http://localhost/plugin/admin</code> is getting to the VirtualFileProvider it doesn't have any View attached at the end. So in the <code>VirtualFileProvider</code>'s Open method the virtual path of <code>~/plugin/admin</code> is being passed in when it should be <code>~/plugin/admin/Index.aspx</code> as defined in my route above. Have I messed up my routes or am I right to be expecting this to happen?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload