我一直在研究一個具有常見功能的項目,特別是我想共享主文件和相關圖像/ 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動詞(不一定會導致任何不好的事情,但是......)。 –