zoukankan      html  css  js  c++  java
  • aspx里构造函数里无法使用session,需要重写一个方法放在load里面就能正常使用session了

    1.构造一个函数,继承System.Web.UI.Page
       /// <summary>
        /// Brand的构造函数
        /// </summary>
        public class CBrandBaseBage : System.Web.UI.Page
        {
           protected string BrandId;
    
           public CBrandBaseBage()
           {
                //ShowPage(); showpage给子类用,如果子类用session[""]=""会提示page里缺少httpmodule的statues
                //this.Init += new EventHandler(Page_Init); 
                this.Load += new EventHandler(BasePage_Load);
            }
           private void BasePage_Load(object sender, EventArgs e)
           {
               ShowPage();//showpage要放在load里面才能正常使用session
               //判断是否存在该品牌BrandId
               
           }
           //抛出一个方法给子类重写
           protected virtual void ShowPage()
           {
               //虚方法代码
           }
    

    2.子页面继承

     //父类虚方法,在Init之前执行
            protected override void ShowPage()
            {
                //base.ShowPage();
                Id = Function.SqlFilter(DtRequest.GetQueryInt("ID", 0).ToString());
                if (Id == "0") return;
                if (string.IsNullOrEmpty(Id)) return;
                if (System.Web.HttpContext.Current == null) return;
                HttpContext.Current.Session["bid"] = Id;
                HttpContext.Current.Session.Timeout = 45;
                Function.WriteCookie("bid", "ZT", Id);
            }
    

      

    你将独自前行,你会遇到友好,也会遇到恶意,不管你多么善良,因为世间就是这样,不好,不坏.
  • 相关阅读:
    P2009 跑步
    P3916 图的遍历
    P2865 [USACO06NOV]路障Roadblocks
    P2820 局域网
    P2176 [USACO14FEB]路障Roadblock
    讨伐!数论
    网络流入门——EK算法
    最被低估的特质
    我的天哪我有博客了!
    Area POJ
  • 原文地址:https://www.cnblogs.com/jsdvkm/p/4584097.html
Copyright © 2011-2022 走看看