简体   繁体   中英

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?

I need to modify an ASP.NET (1.1) application for which the source code was lost. 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). 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' . I am referencing the new assembly in the <assemblies> section of Web.config.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM