自定义继承于Page的基类:MyBasePage
【校验用户是否登录,如果登录则获取用户信息,否则跳转到登录页面】
========================================================
using System; namespace FM.Web { //作用:校验用户是否登录,如果登录则获取用户信息,否则跳转到登录页面 //调用:子类继承此类,override重写Page_Load方法,并调用父类的的Page_Load方法:base.Page_Load(sender,e) public class MyBasePage:System.Web.UI.Page { public Model.Member loginUser {get; set; } protected virtual void Page_Load(object sender, EventArgs e) { loginUser = (Model.Member)Session["user"]; if (loginUser == null) { Response.Redirect("~/Pattern_1/Member/Login.aspx"); } } } }
调用: ================== using System; using System.Collections.Generic; namespace FM.Web.Pattern_1.Shop { public partial class MyOrders :MyBasePage { public BLL.Orders bllOrder = new BLL.Orders(); public List<Model.Orders> modelOrderList = new List<Model.Orders>(); //重写父类的的方法 protected override void Page_Load(object sender, EventArgs e) { base.Page_Load(sender, e);//调用父类的的Page_Load方法 modelOrderList=bllOrder.GetModelList("MemberID=" + this.loginUser.ID); } } }