admin 管理员组文章数量: 1184232
2024年2月20日发(作者:自己怎么做网页链接)
在Global中Application_Error事件处理错误信息
在Global中
protected void Application_Error(Object sender, EventArgs e)
{
Exception objErr = tError().GetBaseException();
string error = "发生异常页: " + ng() + "
";
error += "异常信息: " + e + "
";
rror();
Application["error"] = error;
ct("~/ErrorPage/");
}
中
注:(ct语句在任何情况下都会产生ThreadAbortException异常,但不捕获该异常并不会引起程序中止。如果不设置mode="On",在Application_Error事件会捕获它的异常,中并又回到该过程本身,所以会引起死循环。
ct("~/ErrorPage/",false);这样写的话,mode="On",应该不用设)
1. <%@ Application Language="C#" %>
2.
3.
产生文件不存在的大部分原因是你的Css样式表中使用了不存在的图片。
因为在Exception中有个_httpcode的私有变量,所以要使用HttpException代替来转化捕捉到的异常,
若捕捉到错误代码404(文件不存在)就不记录;
我使用了log4net组件来记录日志,代码如下:
void Application_Error(object sender, EventArgs e)
{
// 在出现未处理的错误时运行的代码
Exception ex = tError().GetBaseException();
if (e().("HttpException"))
{
HttpException httpEx = (HttpException)ex;
int httpCode = pCode();
if (httpCode == 404) return;
}
string m_errorMsg = ;
m_errorMsg = e + "rn" + race;
(m_ng());
}
protected void Application_Error(Object sender, EventArgs e)
{
Exception ex=tError().GetBaseException();
string errorTime="发生时间:"+ng();
string errorAddress=""+ng();
发生异常页: string errorInfo="异常信息:"+e;
string errorSource="错误源:"+;
string errorTrace="堆栈信息:"+race;
rror();
Writer writer=null;
try
{
lock(this)
{
//写入日志
string year=ng();
string month=ng();
string day=ng();
string path=;
string filename=ng("yyyyMMdd")+".txt";
path=h("~/Error/")+year+month+day;
if(!(path))
{
Directory(path);
}
fo file=new FileInfo(path+"/"+filename);
writer=new StreamWriter(me,true);//文件不在则创建,true表示追加
ine("IP:"+stAddress);
ine(errorTime);
ine(errorAddress);
ine(errorInfo);
ine(errorSource);
ine(errorTrace);
ine("-------------------------------------------------------");
用户
}
}
finally
{
if(writer!=null)
{
();
}
}
er("~/"); //跳转到显示友好错误的页面
}
<%@ Application Language="C#" %>
protected void Application_Error(object sender, EventArgs e)
{
// 在出现未处理的错误时运行的代码
Exception objErr = tError().GetBaseException();
if (e() == typeof(HttpException))
{
int i = ((HttpException)objErr).GetHttpCode();
if (i == 404)
{
ct("~/ErrorPage/");
}
else if (i == 403)
{
ct("~/ErrorPage/");
}
}
else
{
string error = ;
string errortime = ;
string erroraddr = ;
string errorinfo = ;
string errorsource = ;
string errortrace = ;
error += ("发生时间:{0}
", ng());
errortime = ("发生时间:{0}", ng());
error += ("发生异常页: {0}
", ng());
erroraddr = ("发生异常页: {0}", ng());
error += ("异常信息: {0}
", e);
errorinfo = ("异常信息: {0}", e);
errorsource = ("错误源:{0}", );
errortrace = ("堆栈信息:{0}", race);
error += "--------------------------------------
";
rror();
Application["error"] = error;
//独占方式,因为文件只能由一个进程写入.
StreamWriter writer = null;
try
{
lock (this)
{
//写入日志
string year = ng();
string month = ng();
string path = ;
string filename = ("{0}.txt",
ng("yyyyMMdd", antInfo));
path = ("{0}{1}/{2}", h("~/Log-File/"),
year, month);
//如果目录不存在则创建
if (!(path))
{
Directory(path);
}
FileInfo file = new FileInfo(("{0}/{1}", path,
filename));
writer = new StreamWriter(me, true);//文件不存在就创建,true表示追加
ine(("stAddress));
ine(errortime);
ine(erroraddr);
ine(errorinfo);
ine(errorsource);
ine(errortrace);
ine("-----------------------------------------------------------------------------------------------------------------");
}
}
finally
用户IP:{0}",
{
if (writer != null)
{
();
}
}
String GoUrl = ("{0}/ErrorPage/?Msg={1}",
main, String(Code("你访问的页面发生未知错误!")));
ct(GoUrl);
}
}
//首先获取当前时间
//在
的onload事件里面加载时间
//定义一个名为TimeShow的Div
一、从服务器端得到
1.在文件中计算时间
DateTime dt;
protected void Application_BeginRequest(Object sender,
EventArgs E)
{
dt = ;
}
protected void Application_EndRequest(Object sender, EventArgs
E)
{
DateTime dt2 = ;
TimeSpan ts = dt2 - dt;
("页面加载的时间" +
ng() + " 毫秒");
}
2.在 中增加如下方法
protected DateTime dt;
protected void Page_Load(object sender, EventArgs e)
{
}
protected override void OnPreInit(EventArgs e)
{
dt = ;
nit(e);
}
protected override void OnLoadComplete(EventArgs e)
{
Complete(e);
TimeSpan ts = - dt;
("加载页面用时:" + illiseconds);
}
二、从客户端来看加载时间
步骤如下:
1.在页面Head部分加入初始时间
2.在Body中加入
3.在需要显示的地方插入一个ID为TimeShow的标签即可
ps:当出现中,如果有一些引用存在于标记中,则不会重命名这些引用,继续吗?这个错误的时!
删除 C:Documents and SettingsAdministratorLocal
SettingsApplication DataMicrosoftWebsiteCache
ps2:修改字体颜色的时候:mentById("TimeShow").innerHTML=
' 加载本页耗时 '+ d1 +'毫秒,请确保您的网络流畅
'
版权声明:本文标题:在Global中Application_Error事件处理错误信息(精品) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1708394825a522536.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论