zoukankan      html  css  js  c++  java
  • (实战篇)如何实现换肤和全站统一友好的错误页面

    承接上一篇的如何实现多语言,这一篇我们讨论的是如何实现换肤,和实现全站统一友好的错误页面,这个比较简单,

    废话不说,直接看思路和实现方法:

    (1)先说换肤:

      总体思路是在基类pagebase里实现,构造方法里重载某个事件

     protected PageBase()
            {
                this.PreInit += new EventHandler(this.Page_PreInit);
            }
       public void Page_PreInit(object sender, EventArgs e)
            {
                if (FWConfig.CurContext.Session[FWConfig.UserInfoSession] != null)
                {
                    string cTheme = Utility.LoginUserInfo.AppTheme;
                    string SkinStr = ConfigurationManager.AppSettings["Skin"];
                    if (CommonFunc.IsNullString(cTheme) || !SkinStr.Contains(cTheme))
                    {
                        cTheme = EnumUtil.SkinType.DefaultTheme.ToString();
                    }
                    this.Page.Theme = cTheme;
                }
               // else 设置默认样式
             } 
     
    
     (2)再说统一友好的错误页面,重载OnError事件
     protected override void OnError(EventArgs e)
            {
                string strRootPath = this.Page.Request.ApplicationPath;
     
                //取得当前具体异常
                try
                {
                    if (null != this.Server.GetLastError())
                    {
                        Exception exError = this.Server.GetLastError().GetBaseException();
                        LogInfoEntity logInfoEntity = new LogInfoEntity
                       {
                           AppName = ConfigurationManager.AppSettings[ "SystemCode"],
                           OperatorUserID = Utility.LoginUserInfo.LoginID,  
                            RequestURL = this.Request.Url.ToString(),
                           MachineIP = this.Request.UserHostAddress,
                           Message = exError.Message,
                           Exception = exError.ToString(),
                           AppCode = ConfigurationManager.AppSetting[ "SystemCode"] };
                        //系统名称
                        //系统编码
                        LogUtil.Error(logInfoEntity, exError);
     
                        //给管理员发送错误邮件
                        #region 给管理员发送错误邮件
     
                        string strReceivers = CommonFunc.ObjectToNullStr(ConfigurationManager.AppSettings["OAErrorMsgRecivers"]);
                        string[] strReceiver = strReceivers.Split(',');
                        for (int i = 0; i < strReceiver.Length; i++)
                        {
                            if (CommonFunc.IsNotNullString(strReceiver[i]))
                            {
                                NotifyMsg msgEntity = new NotifyMsg
                                {
                                    AppCode = "OA",
                                    IsSended = false,
                                    MsgXML = this.CreateWarmXML(exError.Message),
                                    NotifyType = 1,
                                    Reciver = strReceiver[i],
                                    ReciveTime = DateTime.Now,
                                    Sender = "",
                                    SendTime = DateTime.Now,
                                    Subject = "集团新OA系统出错Mail",
                                    TempelateID = "OAErrorMsgTemplate"
                                };
     
                                new ProcTemplate().InsertNotifyMsg(msgEntity);
                            }
                        }
     
                        #endregion 给管理员发送错误邮件
     
                        this.Server.ClearError();
     
                        this.Page.Response.Redirect(strRootPath + "ErrorPage.aspx?errorMsg=" + exError.Message + "&url=" + CommonFunc.ObjectToNullStr(this.Request.Url));
                    }
                }
                catch { }
      
    
    以上是某个项目中的实现方式,当然方式有很都种,这个记录下来以供参考!
  • 相关阅读:
    [转]快速矩阵快速幂
    继续学习C:数字进制表示
    pthread_cond_wait()用法分析
    [原]NYOJ-光棍的yy-655
    [原]NYOJ-组合数-32
    [转]_int64、long long 的区别
    [原]NYOJ-6174问题-57
    [转]sscanf函数具体用法
    [原]NYOJ-A*B Problem II-623
    集存款(复利单利)贷款为一体的计算器(最新版)
  • 原文地址:https://www.cnblogs.com/jangwewe/p/2961716.html
Copyright © 2011-2022 走看看