asp.net – 在使用预编译的Razor视图和VirtualPathProviders时找不到文件PrecompiledApp.config

我们有一个应用程序使用WebForms .aspx文件的一切。 Latley我们一直在使用预编译的RazorViews作为通过简单地在我们的项目中删除一个新的dll来获取nicley打包功能的一种方式。但是现在我们发现我们的预编译视图与我们的VirtualPathProviders有冲突。

从外部dll加载VirtualPathProvider时,应用程序会尝试为所有请求加载precompiledApp.config(而且我们没有得到它)​​。提供者加载了反射。我们在注册的同一个项目中有一些VirtualPathProvider,它们工作正常,但是当我们通过HostingEnvironment.RegisterVirtualPathProvider从外部dll注册提供程序时,我们得到这个问题。

如果我们添加precompiledApp.config文件,它会尝试获取_appstart.cshtml等等。我们必须先下载所有的这些文件,然后再过去:

> precompiledApp.config
> _appstart.cshtml
> _PageStart.cshtml
> _ViewStart.cshtml
> Views / _ViewStart.cshtml
>视图/共享/ _ViewStart.cshtml
> default.cshtml

我们最终在default.cshtml,其余的应用程序工作。由于我们希望使用apsx-files作为认值,这不是一个可以接受的解决方案。我们也担心会出现更多的问题,因为我们不知道为什么会发生这种情况。

我们已经尝试加载我们的提供商,但我们仍然得到相同的错误
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 @R_549_4045@ion 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. @R_549_4045@ion 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,Boolean bFromProxy) +229
   System.IO.FileStream..ctor(String path,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 @R_549_4045@ion: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

解决方法

您确定VirtualPathProvider的FileExists为precompiledApp.config返回false吗?

IsNonUpdatableprecompiledApp标志在实际调用Open之前调用vpp上的FileExists,以防止发生异常。

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....