【问题标题】:ASP.NET MVC VirtualPathProvider not working under IIS 6ASP.NET MVC VirtualPathProvider 在 IIS 6 下不起作用
【发布时间】:2010-06-25 05:24:49
【问题描述】:

通过 ASP.NET MVC 插件架构,Plug-in architecture for ASP.NET MVC

我已经分离了包含资源中视图、css 和 javascript 文件的 DLL(插件)。所以我自己的 VirtualPathProvider 将从 DLL 中加载内容,如果那是插件的话。在开发过程中一切正常。但是一旦我将它部署在 IIS 中,它似乎就不起作用了。 (我在 IIS 6 中映射了 whidcard 并显示了视图)

我已在 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 ?有没有办法解决这个问题?请提供一些启示。

提前致谢。

【问题讨论】:

    标签: asp.net-mvc plugins


    【解决方案1】:

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

    【讨论】:

    • 我已经在 IIS 6 中完成了通配符映射,正如我在帖子中提到的那样。
    • 谢谢,但是对于像localhost/Plugin/MyPlugin.dll/Styles.MyStyles.css 这样的 url 仍然不起作用,我使用 MyVirtualPathProvider 进行了日志记录,它甚至没有通过上面的 url 运行。不过,在 Visual Studio Web 开发服务器中一切正常,有什么线索吗?
    【解决方案2】:

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

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

    【讨论】:

    • 非常感谢您。我开始担心我不得不要求将生产机器升级到 IIS7...
    【解决方案3】:

    在获取包含资源和控制器的外部编译库以在我们的 MVC 环境中工作时,我遇到了许多问题。它在多个项目中使用,并且在不同的项目中出现了不同的错误,所以这是我必须做的所有事情(到目前为止)以确保静态文件处理工作:

    1. 在 web.config 中包含 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();

    【讨论】:

      猜你喜欢
      • 2017-06-03
      • 1970-01-01
      • 2016-08-09
      • 2010-10-12
      • 1970-01-01
      • 1970-01-01
      • 2021-08-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多