首页 新闻 会员 周边 捐助

vs2010 创建控件时出错 请求在此上下文不可用

0
悬赏园豆:20 [待解决问题]

vs2010 创建控件时出错 请求在此上下文不可用

我在app_code有个类继承System.Web.UI.page

#region Web 窗体设计器生成的代码
        override protected void OnInit(EventArgs e)
        {
            InitializeComponent();
            //防止算起来注入
            checkPage();
            //检查是否登录
            checkLogin();

            base.OnInit(e);
            if (!this.DesignMode)
            {
                checkLogin();
                checkPage();
            }
            //仅供测试使用,上线后删除或修改提示信息
            this.Error += new System.EventHandler(PageBase_Error);
        }
        private void InitializeComponent()
        {
            if (!Page.IsPostBack)
            {
                //TODO:权限判断,无权限则提示错误
            }
        }

        //错误处理
        protected void PageBase_Error(object sender, System.EventArgs e)
        {
            string errMsg;
            Exception currentError = Server.GetLastError();
            errMsg = "<link rel=\"stylesheet\" href=\"/style.css\">";
            errMsg += "<h1>系统错误:</h1><hr/>系统发生错误, " +
                "该信息已被系统记录,请稍后重试或与管理员联系。<br/>" +
                "错误地址: " + Request.Url.ToString() + "<br/>" +
                "错误信息: <font class=\"ErrorMessage\">" + currentError.Message.ToString() + "</font><hr/>" +
                "<b>Stack Trace:</b><br/>" + currentError.ToString();
            Response.Write(errMsg);
            Server.ClearError();

        }

        /// <summary>
        /// 防止sql注入
        /// </summary>
        private void checkPage()
        {
            if (Request.QueryString.Count > 0)
            {
                int loop1;
                NameValueCollection coll = Request.QueryString;
                String[] arr1 = coll.AllKeys;
                for (loop1 = 0; loop1 < arr1.Length; loop1++)
                {
                    String[] arr2 = coll.GetValues(arr1[loop1]);
                    int loop2;
                    for (loop2 = 0; loop2 < arr2.Length; loop2++)
                    {
                        string SQL_Repdata = ";--|exec|insert|select|delete|update|count|chr|mid|master|truncate|char|declare|create|drop";
                        String[] arr3 = SQL_Repdata.Split(char.Parse("|"));
                        int loop3;
                        for (loop3 = 0; loop3 < arr3.Length; loop3++)
                        {
                            if (arr2[loop2].ToLower().Trim().IndexOf(arr3[loop3]) > -1)
                            {
                                Response.Write("系统警告:你的行为被系统认定为[非法用户行为]!如有任何疑问,请和网站管理员联系。");
                                Response.Write("<script language='javascript'>function error() {document.location.href='/about/contact.html';} window.setTimeout('error()',3000);</script>");
                                Response.End();
                            }
                        }
                    }
                }
            }           
        }

        /// <summary>
        /// 验证是否登录
        /// </summary>
        private void checkLogin()
        {
            if (Session["adminid"] == null)
            {
                Response.Redirect(ConfigurationManager.AppSettings["urlLogin"].ToString());
            }
        }

 

 

有什么影响吗~!我的控件全部出错~!但运行的时候没有问题~!

 

guoguo1的主页 guoguo1 | 初学一级 | 园豆:80
提问于:2010-12-03 14:58
< >
分享
所有回答(1)
0

DesignMode好像有时不管用,你可以把一些属性做一下null判断再使用,比如Session/Request这些.

I,Robot | 园豆:9783 (大侠五级) | 2010-12-03 22:09
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册