我們有一個應用程序使用WebForms .aspx文件來處理所有內容。 Latley我們一直使用預編譯的RazorView作爲通過在我們的項目中放入一個新的dll來獲得nicley分組功能的一種方式。但是現在我們發現我們的預編譯視圖似乎與我們的VirtualPathProviders衝突。使用預編譯的Razor視圖和VirtualPathProviders時找不到文件PrecompiledApp.config
當從外部dll加載VirtualPathProviders時,應用程序會嘗試爲所有請求加載PrecompiledApp.config(而我們沒有得到它)。提供者被加載反射。我們在與註冊相同的項目中有一些VirtualPathProviders,並且它們工作正常,但是當我們通過HostingEnvironment.RegisterVirtualPathProvider
註冊來自外部dll的提供者時,我們會遇到此問題。
如果我們添加文件PrecompiledApp.config,它會嘗試獲取_appstart.cshtml等等。我們越來越近了exeption之前有下面的所有文件theese:
- PrecompiledApp.config
- _appstart.cshtml
- _PageStart.cshtml
- _ViewStart.cshtml
- 查看/ _ViewStart.cshtml
- Views/Shared/_ViewStart.cshtml
- default.cshtml
我們以default.cshtml結束,其餘的應用程序工作。由於我們想使用apsx文件作爲默認文件,因此這不是一個可接受的解決方案。我們也擔心會出現更多的問題,因爲我們不知道爲什麼會發生這種情況。
我們試圖加載我們提供的這種方式,但我們仍然得到同樣的錯誤: http://sunali.com/2008/01/09/virtualpathprovider-in-precompiled-web-sites/
例外:
Could not find file 'C:\MyApp\PrecompiledApp.config'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.FileNotFoundException: Could not find file 'C:\MyApp\PrecompiledApp.config'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[FileNotFoundException: Could not find file 'C:\MyApp\PrecompiledApp.config'.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +12899479
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath) +2481
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) +229
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) +102
System.Web.Hosting.MapPathBasedVirtualFile.Open() +105
System.Web.WebPages.BuildManagerWrapper.IsNonUpdatablePrecompiledApp() +157
System.Web.WebPages.BuildManagerWrapper..ctor(VirtualPathProvider vpp, IVirtualPathUtility virtualPathUtility) +48
System.Web.WebPages.VirtualPathFactoryManager.<.cctor>b__6() +90
System.Lazy`1.CreateValue() +12776623
System.Lazy`1.LazyInitValue() +355
System.Web.WebPages.ApplicationStartPage.ExecuteStartPage(HttpApplication application) +131
System.Web.WebPages.WebPageHttpModule.StartApplication(HttpApplication application, Action`1 executeStartPage, EventHandler applicationStart) +98
System.Web.WebPages.WebPageHttpModule.InitApplication(HttpApplication application) +75
System.Web.WebPages.WebPageHttpModule.Init(HttpApplication application) +268
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +575
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +352
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +407
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +375
[HttpException (0x80004005): Could not find file 'C:\MyApp\PrecompiledApp.config'.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11700992
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4869221
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272