我目前正在開發一個具有插件式系統的項目。一旦Web項目啓動後,它會查找插件DLL並構建GUI。 dll包含嵌入的視圖,以及嵌入的資源,如圖片或JavaScript。部署後找不到嵌入的Razor視圖(IIS)
我用RazorGenerator(VS插件),以生成的意見,意見的生成操作設置爲「嵌入的資源」和自定義工具設置爲「RazorGenerator」
- 的CS文件
我使用自定義虛擬路徑提供(非常類似於這樣one)
我註冊這個解決辦法我在網上找到了我的虛擬路徑提供(這是必須的,因爲作爲intented它不工作,如果我不使用這個):
var assemblyResourceProvider = new AssemblyResourceProvider(); var hostingEnvironmentInstance = (HostingEnvironment)typeof(HostingEnvironment).InvokeMember("_theHostingEnvironment", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetField, null, null, null); if (hostingEnvironmentInstance == null) return; var mi = typeof(HostingEnvironment).GetMethod("RegisterVirtualPathProviderInternal", BindingFlags.NonPublic | BindingFlags.Static); if (mi == null) return; mi.Invoke(hostingEnvironmentInstance, new object[] { assemblyResourceProvider });
我用這個在我RouteConfig.cs使嵌入的腳本和圖片文件的工作:
routes.IgnoreRoute("{*staticfile}", new { staticfile = @".*\.(css|js|gif|png|jpg|exe)(/.*)?" });
我添加這些行(還有更多),以我的web.config告訴ASP來用我的路徑提供了我的嵌入式來源:
<add name="AspNetStaticFileHandler-PNG" path="*.png" verb="GET,HEAD" type="System.Web.StaticFileHandler"/>
我用Boc.Web.PrecompiledViews DLL以註冊路徑屬性由RazorGenerator
產生BoC.Web.Mvc.PrecompiledViews.ApplicationPartRegistry.Register(assembly);
在Visual Studio中,一切都按照預期工作。嵌入在DLL中的視圖和資源正在顯示並且完美地工作。我也使用IIS 7.5從Visual Studio運行我的Web應用程序。所有的可能性工作:
- 它的工作原理,如果我給由剃刀發生器產生的虛擬路徑(例如:「〜/查看/ ViewTest /測試)
- 它的工作原理,如果我給該DLL資源路徑,它使用我resourceprovider(比如:「DllResources/ViewTest.dll /瀏覽/ ViewTest/Test.cshtml)
然而,當我部署我的web應用程序和使用IIS 7.5,視圖運行它是(僅意見!)沒有顯示!如果i的地址與虛擬路徑(選項1)的意見,IIS給出了這樣的錯誤消息:
The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
如果i地址與DllResources路徑(選項2)的意見,IIS給出了這樣的錯誤消息:
The file '/Views/ViewTest/DllResources/EmbeddedResourceTest/Views/ViewTest/Test.cshtml' has not been pre-compiled, and cannot be requested.
我不知道現在做什麼才能使它工作。我試圖用其他解決方案來取代每一步。結果仍然是一樣的。完美地在VS中工作,但部署後未顯示視圖。
這是IIS的一些配置缺少什麼?我錯過了web.config的東西? 請幫我解決這個問題。
感謝, 諾伯特