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

Reading number is top 10 articles
2个页面间不通过Session与url的传值方式_[Asp.Net教程]
Sql,server一些常见性能问题的总结_[SQL,Server教程]
ASP.NET,2.0“插件”说_.net资料_编程技术
Ajax实例教程-----级联菜单_[AJAX教程]
经典:学习动态网页PHP技术常见问题汇总解答_php资料_编程技术
SEOer如何撰写高质量的优质文章_百度优化_seo学堂
VB.NET使用OracleTransaction处理事务_[Asp.Net教程]
PHP编程中计算时间差的几种方法_php资料_编程技术
创建自定义代码片段 提高CSS布局开发效率_[Html教程]
防止用户上传产生无效文件源码_[Asp.Net教程]
Reading number is top 10 pictures
Distribution of wealth in China survey status report
Ashlynn Brooke a group sexy photo4
刘亦菲写真集1
中国女孩大胆自拍,显露完美身材3
西方气质的东方美女3
西班牙山村小景3
运动的范冰冰1
Sexy women in 2013--1
The household design, do not do bridal chamber a pity
Valentine's day comes, send some cartoon
Download software ranking
仙剑奇侠传98硬盘WINXP版
Sora aoi‘s film--Lust fan wall
Unix video tutorial11
VC++6.0培训教程
超级战舰
c#程序设计案例教程
Sora aoi's film--cangkong_Blue.Sky
Boxer's Top ten classic battle6
Take off clothes to survival
美女游泳记
delv published in(发表于) 2014/1/10 6:28:20 Edit(编辑)
ASP.NET技巧:错误处理封装_[Asp.Net教程]

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

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.