[英]ASP.NET Page directive: inherit codebehind from alternate assembly?
Is it possible to set the Inherits attribute of an ASPX Page directive to a class in an arbitrary assembly? 是否可以将ASPX Page指令的Inherits属性设置为任意程序集中的类?
I need to modify an ASP.NET (1.1) application for which the source code was lost. 我需要修改丢失源代码的ASP.NET(1.1)应用程序。 In a new assembly (foo2.dll) I've created a replacement code-behind class that derives from the original class in the site's code-behind assembly (foo.dll).
在一个新程序集(foo2.dll)中,我创建了一个替换代码隐藏类,该类从网站的代码隐藏程序集(foo.dll)中的原始类派生而来。 It seems easy enough to set the Inherits attribute of the Page directive to the new class name, but when I do that the web server gives me
Could not load type 'Foo2.checkout2'
. 将Page指令的Inherits属性设置为新的类名称似乎很容易,但是当我这样做时,Web服务器却给我提供了
Could not load type 'Foo2.checkout2'
。 I am referencing the new assembly in the <assemblies>
section of Web.config. 我在Web.config的
<assemblies>
部分中引用新程序<assemblies>
。
I don't see anything in the documentation to indicate that this scenario is unsupported, but I'm not certain that it is, either. 我没有在文档中看到任何内容表明该方案不受支持,但我也不确定。
Original 原版的
<%@ Page Inherits="Foo.checkout" language="c#" Codebehind="checkout.aspx.cs" AutoEventWireup="false" %>
New 新
<%@ Page Inherits="Foo2.checkout2" CodeFile="checkout2.aspx.cs" CodeFileBaseClass="Foo.checkout" language="c#" Codebehind="checkout.aspx.cs" AutoEventWireup="false" %>
Yes that is possible. 是的,那是可能的。 You have to add a reference like this
您必须添加这样的参考
It did not change the web.config but I had the reference in .csproj <ItemGroup />
section like this 它没有更改web.config,但我在.csproj
<ItemGroup />
部分中有这样的引用
<Reference Include="WebApplication2, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\WebApplication2\bin\WebApplication2.dll</HintPath>
</Reference>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.