BuildManager解决页面继承 [英] BuildManager Resolving Page Inheritance

查看:195
本文介绍了BuildManager解决页面继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了的VirtualPathProvider以更改aspx页面加载到我的ASP.Net应用程序。由于这个过程中,我已删除了code隐藏的文件,我只是ascerting我的页面从一个特定的页面类继承的一部分。 例如:

I have written a VirtualPathProvider to change how aspx pages are loaded into my ASP.Net application. As part of this process I have removed Code-Behind files and I am simply ascerting that my page inherits from a particular page class. eg:

<%@ Page Language="C#" AutoEventWireup="true" Inherits="Namespace.PageClass" %>

如果我这样做,我得到以下异常:

If I do this I get the following exception:

HttpParseException未能加载类型   Namespace.PageClass

HttpParseException Could not load type 'Namespace.PageClass'

我也试过如下:

<%@ Page Language="C#" AutoEventWireup="true" Inherits="Namespace.PageClass, AssemblyName" %>

这将产生以下错误:

HttpParseException   无法加载程序集   的AssemblyName。请确保它是   访问页面之前编译。

HttpParseException Could not load the assembly 'AssemblyName'. Make sure that it is compiled before accessing the page.

在应用程序启动时我加载所需的组件到当前应用程序域:

When the application starts I load the required Assembly into the current App domain:

AppDomain.Current.Load(...)

目前我假设的问题在于BuildManager的解决了命名空间/装配基准的能力....但如果​​诚实的...这是一个猜测: - )

At the moment I am assuming the problem lies with the BuildManager's ability to resolve the Namespace/Assembly reference.... but if honest... that's a guess :-)

是任何人都能够阐明这个一些轻?

Is anyone able to shed some light on this?

推荐答案

您的网页必须使用完整指定类的位置 - 即继承=MyNamespace.MyClass,MyAssembly程序

Your page must use the full specified class location - i.e. Inherits="MyNamespace.MyClass, MyAssembly".

然后装载组件插入的AppDomain是不会帮助的AppDomain解决。它不走的动态加载的程序集。所以,你必须认购AppDomain.ResolveAssembly事件。

Then loading the assembly into the appDomain is not going to help AppDomain resolve it. It doesn't walk the dynamically loaded assemblies. So you must subscribe for the AppDomain.ResolveAssembly event.

private Assembly myDynamicAssembly = null;

protected void Application_Start( object sender, EventArgs e )
{
      myDynamicAssembly = Assembly.LoadFrom( Server.MapPath( "MyLocation/MyAssembly.dll" ) );

      AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler( CurrentDomain_AssemblyResolve );
}

Assembly CurrentDomain_AssemblyResolve( object sender, ResolveEventArgs args )
{
      if ( args.Name == "MyAssembly" )
      {
           return myDynamicAssembly;
      }

      return null;
}

和你就大功告成了。现在,运行时知道如何从这种动态加载的程序集解析类。

And you're done. Now the runtime knows how to resolve classes from this dynamically loaded assembly.

这篇关于BuildManager解决页面继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆