【问题标题】:ASP.NET Page directive: inherit codebehind from alternate assembly?ASP.NET 页面指令:从备用程序集继承代码隐藏?
【发布时间】:2011-02-24 15:07:41
【问题描述】:

是否可以将 ASPX Page 指令的 Inherits 属性设置为任意程序集中的类?

我需要修改丢失源代码的 ASP.NET (1.1) 应用程序。在一个新程序集 (foo2.dll) 中,我创建了一个替换代码隐藏类,它派生自站点的代码隐藏程序集 (foo.dll) 中的原始类。将 Page 指令的 Inherits 属性设置为新的类名似乎很容易,但是当我这样做时,Web 服务器会给我Could not load type 'Foo2.checkout2'。我在 Web.config 的 <assemblies> 部分引用了新程序集。

我在文档中没有看到任何内容表明此方案不受支持,但我也不确定是否支持。

原创

<%@ Page Inherits="Foo.checkout" language="c#" Codebehind="checkout.aspx.cs" AutoEventWireup="false" %>

新的

<%@ Page Inherits="Foo2.checkout2" CodeFile="checkout2.aspx.cs" CodeFileBaseClass="Foo.checkout" language="c#" Codebehind="checkout.aspx.cs" AutoEventWireup="false" %>

【问题讨论】:

  • 您是否尝试将 dll 放入站点的 bin 目录中?
  • 是的,Foo2.dll 在站点的 bin 目录中。

标签: asp.net


【解决方案1】:

是的,这是可能的。您必须添加这样的参考

它没有更改 web.config,但我在 .csproj &lt;ItemGroup /&gt; 部分中有这样的参考

<Reference Include="WebApplication2, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\WebApplication2\bin\WebApplication2.dll</HintPath>
    </Reference>

【讨论】:

  • 但是 .csproj 只能被 Visual Studio 读取,而不能被 .NET/IIS 读取。编译期间是否使用此参考?由于我没有原始应用程序的源代码,因此我没有在 VS 中打开它或重新编译它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-19
相关资源
最近更新 更多