BasePage基类

2011-1-7 14:23:04 - tanlixiao

      一般我们管理系统的后台程序页面是由权限限制的,但是我们不可能在每个限制的页面进行权限的判断,所以我们就定义一基类,在页面加载前进行判断是否登陆或是否有权限打开本页面,就定义一基类BasePage,后台需要判断权限的页面就继承它,我们也可以在这页面加监控,当页面报错时可在这页面处理;
代码如下:

public class BasePage : System.Web.UI.Page
    {
        public static
string domain =
System.Configuration.ConfigurationManager.AppSettings["URL"].ToString();
       
public static string cssdomain =
System.Configuration.ConfigurationManager.AppSettings["cssPath"].ToString();
       
public static string jsdomain =
System.Configuration.ConfigurationManager.AppSettings["jsPath"].ToString();
       
public static string imgdomain =
System.Configuration.ConfigurationManager.AppSettings["imgPath"].ToString();

protected void Page_PreInit(object obj, EventArgs args)      
{
if(Session["sessionName"]==null){
Response.Redirect("logout");
}
}
 #region 出错处理
 protected override void OnInit(EventArgs e)
 {
            this.Error = new System.EventHandler(this.Page_Error);
            base.OnInit(e);
       
}
  public static Hashtable ErrorTable = new Hashtable();
       
protected void Page_Error(object sender, System.EventArgs e)   
{
  try
   {
     Exception ex = Server.GetLastError();
     string url = Request.Url.AbsolutePath;
     string msg = ex.Message;
     if (ErrorTable.Contains(url)) { return; }
     else
      {
        //没找到
        ErrorTable.Add(url, msg);
       }
if (Request.Form != null)
       {
         if (Request.Form.ToString().Length > 8800) {
msg = System.Environment.NewLine "接收Form:"
Server.UrlDecode(BComm.GetPreSubString(Request.Form.ToString(), 100) "..."
BComm.GetEndSubString(Request.Form.ToString(), 2000)); }
        else {
msg = System.Environment.NewLine
 "接收Form:" Server.UrlDecode(Request.Form.ToString()); }
          }
if (Request.QueryString != null)
                    msg = System.Environment.NewLine
"接收QueryString:" Server.UrlDecode(Request.QueryString.ToString());
if (Request.UrlReferrer != null)
                {
                    msg = System.Environment.NewLine "来源:"
 Request.UrlReferrer.AbsoluteUri;
                }
               
//发送邮件
                System.Text.StringBuilder sbMM = new System.Text.StringBuilder();
                sbMM.Append(url System.Environment.NewLine msg);
                sbMM.Append(System.Environment.NewLine ex.StackTrace.ToString());
                BComm.SendEmailTo(sbMM.ToString());
            }
            catch (Exception exe)
            {
                string aa = exe.Message;
            }
        }
        #endregion
    }

标签:BasePage

关于我

喜欢简简单单的生活.

记录平凡世界的点滴

-于2010年12月31日

联系我

  • 微信:fishren
  • 邮箱:
    tanlixiao@163.com
  • Address:
    中国最南端的滨海城市
    河西区 解放路 502