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.