zoukankan      html  css  js  c++  java
  • asp.net网站项目调用page,或者ashx页面不能用反射

    public class TestHandler : System.Web.IHttpHandler
        {
            public bool IsReusable
            {
                get { return false; }
            }
    
            public void ProcessRequest(System.Web.HttpContext context)
            {
                Page page = BuildManager.CreateInstanceFromVirtualPath("~/webform1.aspx", typeof(WebForm1) ) as Page; 
    // WebForm1是你要加载页面对应的后台类
                page.ProcessRequest(context);
    
            }
        }
    public partial class fanshe : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            IHttpHandler page =BuildManager.CreateInstanceFromVirtualPath("/ascx/test.ashx", typeof (IHttpHandler)) as IHttpHandler;
            page.ProcessRequest(HttpContext.Current);
        }
    }

    页面对应的类是动态编译的,所以不会出现在 Assembly 中,也无法通过反射取得。
    除了用上面的方法加载页面,也可以在 @Page 指令中指定 ClassName,然后可以直接 new 这个page(当然前提是页面要已经访问过了precompiled)

  • 相关阅读:
    Java中静态字段和静态方法
    Java抽象方法、抽象类以及接口
    Java单例模式
    java继承
    java构造方法
    java方法
    Java常量与变量
    Java初识
    1
    补码,反码,加减法运算,类型取值范围
  • 原文地址:https://www.cnblogs.com/uxinxin/p/6279144.html
Copyright © 2011-2022 走看看