The session is not available in the ASPX constructor, and you need to rewrite a method to put it in load to use the session normally.

Source: Internet
Author: User

1. Construct a function that inherits System.Web.UI.Page
   <summary>///    brand's constructor///    </summary> public    class CBrandBaseBage:System.Web.UI.Page    {       protected string brandid;       Public Cbrandbasebage ()       {            //showpage (); ShowPage for subclasses, if the subclass uses session[""]= "" will prompt the page missing HttpModule statues            //this. Init + = new EventHandler (Page_Init);             This. Load + = new EventHandler (basepage_load);        }       private void Basepage_load (object sender, EventArgs e)       {           showpage ();//showpage must be placed in Load to use session normally           //To determine the existence of the brand Brandid                  }       Throws a method to subclass rewrite       protected virtual void ShowPage ()       {           //virtual method code       }

2. Child page Inheritance

The parent virtual method that executes        protected override void ShowPage ()        {//base before init            . 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 =;            Function.writecookie ("Bid", "ZT", Id);        }

  

The session is not available in the ASPX constructor, and you need to rewrite a method to put it in load to use the session normally.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.