gpt4 book ai didi

.net - ASP .NET 虚拟路径提供程序 HttpCompileException

转载 作者:行者123 更新时间:2023-12-02 05:13:08 26 4
gpt4 key购买 nike

我有一个 VirtualPathProvider 正在从数据库加载我的 aspx 文件内容。一切似乎都很好,除非我的 aspx 文件引用了我的 web.config 中未明确提及的命名空间或程序集。

解决方案似乎很简单,对吧?向页面添加程序集和导入指令......但这似乎不起作用。我仍然收到以下 HttpCompileException:

    c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET 
Files\app.server\70480a40\2a773b44\App_Web_test.aspx.e7cf0b6b.mzeindht.0.cs(183): error CS0234:
The type or namespace name 'Model' does not exist in the namespace 'MyApp.Data' (are you missing an assembly reference?)

尽管如此,在我保存在数据库中的 test.aspx 页面中,我有:

<%@ Assembly Name="MyApp.Data" %>
<%@ Import Namespace="MyApp.Data" %>
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MyApp.Data.Model.TestModel>" %>

<asp:Content ContentPlaceHolderID="MainContent" runat="server">
</asp:Content>

现在,我已经知道 MyApp.Data 已经加载到 AppDomain 中(我在运行时通过检查 AppDomain.CurrentDomain.GetAssemblies() 进行了验证)并且我知道没有失败的请求加载 MyApp .Data 程序集(因为我已经绑定(bind)到 AppDomain.ResolveAssembly 事件并且它没有在异常发生之前触发)。此外,如果我将程序集目录中的名称更改为 MyApp.Data123(伪造的名称),页面会在尝试加载程序集时崩溃。

如果我从页面中完全删除程序集指令,那么我会得到命名空间 The type or namespace name 'MyApp' could not be found...所以在那里使用程序集指令似乎有点帮助...

知道我在这里缺少什么吗?谢谢。

最佳答案

.NET VirtualPathProviders and Pre-Compilation 可能重复

If a Web site is precompiled for deployment, content provided by a VirtualPathProvider
instance is not compiled, and no VirtualPathProvider instances are used by the precompiled
site.

关于.net - ASP .NET 虚拟路径提供程序 HttpCompileException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3649091/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com