All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
用ASP.NET2.0如何随机读取Access记录?_[Asp.Net教程]
ASP.NET,2.0中客户端脚本总结_[Asp.Net教程]
ASP.NET的错误处理机制_[Asp.Net教程]
PHP技巧:通过实例深入剖析require和include的用法_[PHP教程]
无刷新仿google波形扭曲彩色Asp.net验证码_[Asp.Net教程]
Asp.Net实例:根据IP获取当地天气预报的实现_[Asp.Net教程]
c#,MD5加密算法的一个实例_[Asp.Net教程]
C#教程:C#中的显示类型转换
加大MYSQL中的最大连接数的两种方法_php资料_编程技术
SQL2005中的事务与锁定(七)_mssql学习_编程技术
Reading number is top 10 pictures
Shandong jinan is about to dismantle a one hundred-year history of the building
Summer is most suitable for young people to travel in China4
Beauty shocked Japan Tokyo motor show model
Startling Russian girl blind date scene3
随便发几张图
乳娘帕梅拉安德森4
非笑不可:最强爆笑图片精选
The Soviet union swimsuit exposure in the 70 year2
Plump, too plump!2
Entered the goddess in the AD1
Download software ranking
网页特效实例大全
ASP.NET.2.0.XML.高级编程(第3版)
C#高级编程(第4版)
Boxer's Top ten classic battle4
SQL2000 For 4IN1
中国结婚习俗实录
Unix video tutorial17
Tram sex maniac 2 (H) rar bag7
美女游泳记
SP3 for SQL2000
delv published in(发表于) 2014/1/10 6:28:23 Edit(编辑)
ASP.NET技巧:错误处理封装_[Asp.Net教程]_0

ASP.NET技巧:错误处理封装_[Asp.Net教程]_0

ASP.NET技巧:错误处理封装_[Asp.Net教程]

/*----------------------------------------------------------------
* Copyright (C)
* 版权所有。
*
* 文件名 :ErrorManager.cs
* 功能描述:asp.net中统一的错误修理,与本类相配套需要增加一个错误信息显示页面,如error.aspx
*
* 使用说明:1. 在Application_Start()中启动定时器(定时清空错误信息):ErrorManager.Instance.Start(),
* 默认12小时运行一次,或用ErrorManager.Instance.SetTimerInterval()设置。
* 2. 在Application_Error()中,当发生错误时,保存这个错误信息并转到error.aspx中显示这个错误
* string key = ErrorManager.Instance.AddError();
* Response.Redirect("error.aspx?key=" + key);
* 3. 在error.aspx中通过url传来的key,取得并显示错误信息:
* string err = ErrorManager.Instance.GetError(key)
* err中前19个字符是错误发生的时间,后面是错误信息。
* 4. 为了捕捉Session超时的错误,而不是返回Session[key]是null的错误信息,本类增加了GetSession()
* 和SetSession函数来统一管理Session,以后aspx中不能直接读取Session,而必须通过本类来读取。
*
*
* 创建标识:
*
* 修改标识:
* 修改描述:
*
* 修改标识:
* 修改描述:
*----------------------------------------------------------------*/
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;


/**////


/// Summary description for Error
///

public class ErrorManager
{
private System.Timers.Timer m_timer;
private Hashtable m_htErr;


/**////


/// 私有的构造函数
///

private ErrorManager()
{
this.m_timer = new System.Timers.Timer();
this.m_timer.Enabled = false;
this.m_timer.Interval = 12 * 60 * 60 * 1000; //默认12个小时执行一次
this.m_timer.Elapsed += new System.Timers.ElapsedEventHandler(m_timer_Elapsed);
this.m_htErr = new Hashtable();
}


/**////


/// 单例模式的接口
///

public static readonly ErrorManager Instance = new ErrorManager();


/**////


/// 设置定时器的频率,单位是毫秒
///

/// 毫秒
public void SetTimerInterval(int Interval)
{
this.m_timer.Interval = Interval;
}


/**////


/// 定时器开始
///

public void TimerStart()
{
this.m_timer.Enabled = true;
}


/**////


/// 定时器结束
///

public void TimerStop()
{
this.m_timer.Enabled = false;
}


/**////


/// 发生了一个错误,把错误信息保存起来,并返回错误的id,便于页面中读取
///

/// 返回错误的id
public string AddError()
{
string key = Guid.NewGuid().ToString();
string msg = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+ HttpContext.Current.Server.GetLastError().GetBaseException().Message;
this.m_htErr.Add(key, msg);


HttpContext.Current.Server.ClearError();


return key;
}


/**////


/// 返回指定Key的错误信息,前19个字符是错误发生的时间
///

/// key,是一个guid
/// 返回错误信息
public string GetError(string key)
{
return this.m_htErr[key].ToString();
}


/**////


/// 定时在Hashtable中清理错误信息
///

///
///
private void m_timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
ArrayList list = new ArrayList();
lock (this.m_htErr)
{
DateTime now = DateTime.Now;
TimeSpan ts;
foreach (string key in this.m_htErr.Keys)
{
//前19个字符是错误发生的日期,yyyy-MM-dd HH:mm:ss
string time = this.m_htErr[key].ToString().Substring(0, 19);
ts = now - Convert.ToDateTime(time);
if (ts.TotalMinutes > 20) //把20分钟前的错误信息从hashtable中清除
list.Add(key);
}


foreach (string key in list)
{
this.m_htErr.Remove(key);
}
}


}


Session操作的封装#region Session操作的封装
/**////


/// 取得指定键值的Session
///

/// 键值
/// 键内容值
public object GetSession(string key)
{
object val = HttpContext.Current.Session[key];
if (val == null)
throw new Exception("页面超时,请重新登录。");


return val;
}


/**////


/// 设置Session
///

/// 键值
/// 键内容
public void SetSession(string key, object val)
{
HttpContext.Current.Session[key] = val;
}
#endregion
}


来源:网络







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.