2010-06-25 55 views
2

下工作,通过ASP.NET MVC的插件架构,Plug-in architecture for ASP.NET MVCASP.NET MVC的VirtualPathProvider不是IIS 6

我已经分居DLL(插件),其中包含在资源的意见,CSS和JavaScript文件。所以我自己的VirtualPathProvider会从DLL中加载内容,如果是插件的话。它在开发过程中一切正常。但是一旦我将它部署在IIS中,它似乎不起作用。 (I映射whidcard在IIS 6和视图被示出)

我已经注册我在global.asax中的VirtualPathProvider作为

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

例如。 http://localhost/Plugin/MyPlugin.dll/Styles.MyStyles.css

这应该从plugin.dll被加载,但IIS返回404

我猜的静态文件都是由IIS处理,并通过asp.net和我的VirtualPathProvider不是去了?有办法解决这个问题吗?请说明一下。

在此先感谢。

回答

1

我找到了解决方法,在web.config httpHandlers元素中添加了staticFileHandler。

<add verb="GET,HEAD,POST" path="*" type="System.Web.StaticFileHandler" validate="true" /> 
+0

非常感谢你。我开始担心我不得不要求将生产机器升级到IIS7 ...... – Greg 2011-06-21 17:07:32

2

如果这是IIS 6,您将需要通配符映射。见Phil Haack的this blog post

+0

我已经在IIS 6中完成了通配符映射,正如我在文章中提到的那样。 – 2010-06-25 23:06:45

+0

谢谢,但仍然不能用于像http://localhost/Plugin/MyPlugin.dll/Styles.MyStyles这样的网址。css 我使用我的MyVirtualPathProvider进行了日志记录,它甚至没有运行上面的url。一切工作正常在Visual Studio Web开发服务器,但任何线索? – 2010-06-26 03:40:44

0

我有一些获得含资源和控制器在我们的MVC环境中工作的外部编译库的问题。它在多个项目中使用,不同的错误都在不同的项目浮出水面所以这里所有的事情我不得不这样做(到目前为止),以确保静态文件处理工作:

  1. 在web.config中包括StaticFileHandler,如:

    <添加动词= “GET,HEAD” 路径= “* JS” NAME = “静态的JS” TYPE = “System.Web.StaticFileHandler”/ >

  2. 确保静态项在路由忽略:

    routes.IgnoreRoute(“{* staticfile}”,new {staticfile = @“。 * \ (CSS | JS | GIF | JPG格式)(/ *。)“});

  3. 注册一个虚拟路径提供,如:?

    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. 不需要对静态文件,但值得一提的是获取视图/控制器工作所需的内容,即添加MVCContrib并注册嵌入式视图引擎:

    PortableAreaRegistration.RegisterEmbeddedViewEngine();