ControlBuilderInterceptor 类

利用 ControlBuilderInterceptor 类即可自定义或控制编译过程。

语法

internal class ControlBuilderInterceptor

警告

ControlBuilderInterceptor 类是内部的,不应在代码中直接使用。

如“注解”部分所述,可以检查此类型是否存在,以确定是否为侦听器类型提供了支持。 在任何情况下,Microsoft 都不支持在生产应用程序中将此类用作其他用途。

注解

在 .NET Framework 2.0 和 .NET Framework 3.5 中,2020 年 8 月更新添加了对使用侦听器类型自定义或控制编译过程的支持。 可使用 Type.GetType() 检查是否存在 ControlBuilderInterceptor 类型,以此确定是否提供了该支持。

Type type = Type.GetType("System.Web.Compilation.ControlBuilderInterceptor, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");

如果返回值不为 NULL,则为侦听器提供了支持。 如果返回值为 null,或引发异常,则表示尚未安装 2020 年 8 月更新,且未提供侦听器支持。

如果提供了侦听器支持,可以编写和注册将与编译过程交互的侦听器类型,其操作方式与 ControlBuilderInterceptor 在更高版本的 .NET Framework 中的方式相同。 在 .NET Framework 2.0 和 .NET Framework 3.5 中,侦听器类型可以是满足以下要求的任何类:

使用 ASP.NET 应用程序设置 (<appSettings>) 中的 aspnet:20ControlBuilderInterceptor 键注册侦听器类型。 此应用程序设置必须在计算机或应用程序 web.config 文件中列出。 使用侦听器的程序集限定类型名称指定侦听器类型。 以下示例演示如何注册名为 Fabrikam.Interceptor 的侦听器类型。

<configuration>
  ...
  <appSettings>
    ...
    <add key="aspnet:20ControlBuilderInterceptor"
         value="Fabrikam.Interceptor, Fabrikam, Version=1.0.0.0, Culture=neutral, PublicKeyToken=2b3831f2f2b744f7" />
  </appSettings>
</configuration>

若要检索类型的程序集限定名称,请使用 Type.AssemblyQualifiedName 属性,如以下代码所示。

string assemblyQualifiedName = typeof(Fabrikam.Interceptor).AssemblyQualifiedName;

若存在侦听器支持,编译过程会按上述方式与所列类型交互。 若侦听器支持不存在,应用程序设置会被忽略,且不起作用。

要求

命名空间:System.Web.Compilation

程序集:System.Web(在 System.Web.dll 中)

.NET Framework 版本:3.5、2.0