2

By ASP.NET MVC plugin architecture, Plug-in architecture for ASP.NET MVC

I have separated DLL(plugin) which contains the views, css and javascript files in the resources. So my own VirtualPathProvider will load the content out from the DLL if that is for the plugin. It works all fine during development. But It appears not working once I deployed it in IIS. (I mapped the whidcard in IIS 6 and the views are showing)

I have registered my VirtualPathProvider in global.asax as

protected void Application_Start()
{
    RegisterRoutes(RouteTable.Routes);
    HostingEnvironment.RegisterVirtualPathProvider(new MyVirtualPathProvider());
}

For example. http://localhost/Plugin/MyPlugin.dll/Styles.MyStyles.css

This should be loaded from the plugin.dll but IIS returns 404.

I guess the static files are all handled by the IIS and not went through asp.net and my VirtualPathProvider ? Is there way to get around this? Please shed some light.

Thanks in advance.

Community
  • 1
  • 1
Ray Lu
  • 26,208
  • 12
  • 60
  • 59

3 Answers3

2

If this is IIS 6 you will need a wildcard mapping. See this blog post from Phil Haack.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • I have done the wildcard mapping in IIS 6 as I mentioned in the post. – Ray Lu Jun 25 '10 at 23:06
  • Thanks, but still doesn't work for the url like http://localhost/Plugin/MyPlugin.dll/Styles.MyStyles.css I placed logging with my MyVirtualPathProvider, it wasn't even running by the url above. everything works fine within Visual studio web development server though, any clue? – Ray Lu Jun 26 '10 at 03:40
1

I've found the workaround by adding the staticFileHandler in the web.config httpHandlers element.

<add verb="GET,HEAD,POST" path="*" type="System.Web.StaticFileHandler" validate="true" />
Ray Lu
  • 26,208
  • 12
  • 60
  • 59
  • Thank you so much for this. I was starting to worry I'd have to ask to upgrade production machines to IIS7... – Greg Jun 21 '11 at 17:07
0

I've had a number of problems getting an external compiled library containing resources and controllers to work in our MVC environment. It's used across multiple projects and different errors have surfaced in different projects so here's all the things I had to do (so far) to ensure static file handling works:

  1. Include StaticFileHandler in web.config, e.g.:

    <add verb="GET,HEAD" path="*.js" name="Static for js" type="System.Web.StaticFileHandler" />

  2. Ensure Static items are ignored in routing:

    routes.IgnoreRoute("{*staticfile}", new { staticfile = @".*\ .(css|js|gif|jpg)(/.*)?" });

  3. Register a Virtual Path Provider, e.g.:

        System.Web.Hosting.HostingEnvironment.RegisterVirtualPathProvider(new EmbeddedResourceVirtualPathProvider.Vpp(assemblies.ToArray())
        {
            //you can do a specific assembly registration too. If you provide the assemly source path, it can read
            //from the source file so you can change the content while the app is running without needing to rebuild
            //{typeof(SomeAssembly.SomeClass).Assembly, @"..\SomeAssembly"} 
        });
    
  4. Not required for static files but worth mentioning are what was needed to get the views / controllers working, which was adding MVCContrib and registering the embedded view engine:

    PortableAreaRegistration.RegisterEmbeddedViewEngine();

The Coder
  • 4,981
  • 2
  • 29
  • 36