(实战篇)如何实现换肤和全站统一友好的错误页面
承接上一篇的如何实现多语言,这一篇我们讨论的是如何实现换肤,和实现全站统一友好的错误页面,这个比较简单,
废话不说,直接看思路和实现方法:
(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 { }
以上是某个项目中的实现方式,当然方式有很都种,这个记录下来以供参考!