我一直在研究一个具有常见功能的项目,特别是我想共享主文件和相关图像/ js/etc。为此,母版页及其相关文件全部封装到所有“子项目”使用的“全局”DLL中。这一切都在开发中发挥了很大作用,但部署产生了惊喜,似乎引起了许多人的不安:VirtualPathProvider
在预编译时不起作用。VirtualPathProvider没有(完全)在IIS 7.5上生产工作
现在感谢this blog post containing a workaround我能够再次试图让它工作。遗憾的是,它仍然没有。
我选择摆脱我Global.asax
执行和去与博客文章的AppInitialize
做法:
public static class AppStart
{
public static void AppInitialize()
{
HostingEnvironment hostingEnvironmentInstance = (HostingEnvironment)typeof(HostingEnvironment).InvokeMember("_theHostingEnvironment", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetField, null, null, null);
MethodInfo mi = typeof(HostingEnvironment).GetMethod("RegisterVirtualPathProviderInternal", BindingFlags.NonPublic | BindingFlags.Static);
mi.Invoke(hostingEnvironmentInstance, new object[] { new MasterPageProvider() });
}
}
由于实际提供商调试工作,我将不包括它。如果你想看到它,不要犹豫,问。只是想尽量缩短问题的范围。
整个情况的一个有趣的方面是生产不会产生无法找到母版页的错误。对我来说,这意味着供应商的工作是,但无论如何,其他资源(js/css/etc)都不能正确地从程序集中检索。
所以我的问题归结为这个:这个解决方案在开发中的工作原理是什么,但在IIS 7.5上的生产中没有?
UPDATE 2011年11月20日
尝试了大卫博的建议,并没有结果很遗憾。我的web配置现在看起来是这样的:
<configuration>
<connectionStrings>
<clear />
<!-- ... -->
</connectionStrings>
<system.web>
<pages>
<controls>
<!-- ... -->
</controls>
</pages>
<compilation debug="true" targetFramework="4.0" />
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
</configuration>
UPDATE 2011年11月21日
只是为了验证我的怀疑,是的VirtualPathProvider实际工作,我注释掉第三行( mi.Invoke(....
)并重新部署该网站。正如我所怀疑的,现在由于无法找到MasterPage文件而中断。此问题似乎只与通过VPP传递的静态文件有关。
下班后我会给你一个镜头。这似乎是我的最新发现(至少一切都适合)的答案。感谢你的协助! –
非常感谢您的帮助。这一直困扰我几个星期了!我之前曾经遇到过这种情况,但没有考虑到IIS现在自己提供静态文件。享受225代表! –
如果你愿意扩大你的答案,你应该提到你需要每个扩展一个处理程序。另外,我不相信你需要POST动词(不一定会导致任何不好的事情,但是......)。 –