error.aspx.cs

来自「具有一般blog的相册、文章、作品等功能程序结构也比较清晰采用三层结构开发(利用」· CS 代码 · 共 76 行

CS
76
字号
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace liuwei
{
	/// <summary>
	/// error 的摘要说明。
	/// </summary>
	public class error : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Image ErrorImage;
		protected System.Web.UI.WebControls.Label lbErrorMessage;

		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			string noExceptionFound = "没有详细错误信息,请与管理员联系.";
			StringBuilder exceptionMsgs = new StringBuilder();
				
			Exception ex = Server.GetLastError().GetBaseException();//.GetBaseException();
			while (null != ex) 
			{
				if (ex is System.IO.FileNotFoundException)
				{
					exceptionMsgs.Append("<p>系统找不到这个页面。</p>");
					ErrorImage.ImageUrl = "images/system_error_404.gif";
				}
				else
				{
					exceptionMsgs.AppendFormat("<p>{0}</p>", ex.Message);
				}

				ex = ex.InnerException;
			}
			
			Server.ClearError();

			if(exceptionMsgs.Length == 0)
			{
				exceptionMsgs.Append(noExceptionFound);
			}

			this.lbErrorMessage.Text = exceptionMsgs.ToString();
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);
		}
		#endregion
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?