日期:2014-05-17 浏览次数:20424 次
public class BasePage : System.Web.UI.Page { public BasePage() { this.Load += new System.EventHandler(Rank); } private void Rank(object sender, EventArgs e) { if (Session["username"] == null) { Response.Redirect("~/MyLogin.aspx"); } } protected override void OnInit(EventArgs e) { if (Session["username"] == null) { Response.Redirect("~/MyLogin.aspx"); } base.OnInit(e); } }
//需检查权限的页面 public partial class Questions : MyPage { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ((SiteMaster)this.Master).CheckPermition(OES2.MyAccount.AccountRole.教师, "", 6); } } } //模板页 public void CheckPermition(MyAccount.AccountRole BaseRole,string Title,int selectedIndex) { ShowTitle(Title,selectedIndex); if (BaseRole == MyAccount.AccountRole.未定义) { MainContent.Visible = true; HasErr = false; ErrorState = ""; if (MyAccount.IsAccessed(Common.AccountSession, MyAccount.AccountRole.登录用户)) { div_unreged.Style.Add(HtmlTextWriterStyle.Display, "none"); div_reged.Style.Add(HtmlTextWriterStyle.Display, "inline"); } else { div_unreged.Style.Add(HtmlTextWriterStyle.Display, "inline"); div_reged.Style.Add(HtmlTextWriterStyle.Display, "none"); } } else { if (MyAccount.IsAccessed(Common.AccountSession, BaseRole)) { MainContent.Visible = true; HasErr = false; ErrorState = ""; div_unreged.Style.Add(HtmlTextWriterStyle.Display, "none"); div_reged.Style.Add(HtmlTextWriterStyle.Display, "inline"); } else { MainContent.Visible = false; HasErr = true; ErrorState = "-1"; div_unreged.Style.Add(HtmlTextWriterStyle.Display, "inline"); div_reged.Style.Add(HtmlTextWriterStyle.Display, "none"); } } }
------解决方案--------------------
OnInit 就行了
------解决方案--------------------
OnInit 里进行控制 足以