日期:2014-05-19  浏览次数:20560 次

有经验的朋友描述一下如何在服务器处理中发生内部error的时候,把其详细错误信息(包括错误堆栈)显示在自定义的aspx页面
汗,题目有些长,那就如题吧

------解决方案--------------------
try{
....
}
catch(Exception ex)
{
Response.Write(ex.ToString());
}

然而这样写有点不伦不类,也太偷懒了,一点不像是认真设计过的程序。

你确实应该把问题提的具体一些。
------解决方案--------------------
在系统自动生成的Web.Config文件里可以自己定义的
<system.web>
<!--
设置 compilation debug= "true " 将调试符号插入
已编译的页面中。但由于这会
影响性能,因此只在开发过程中将此值
设置为 true。
-->
<compilation debug= "true "/>
<!--
通过 <authentication> 节可以配置 ASP.NET 使用的
安全身份验证模式,
以标识传入的用户。
-->
<authentication mode= "Windows "/>
<!--
如果在执行请求的过程中出现未处理的错误,
则通过 <customErrors> 节可以配置相应的处理步骤。具体说来,
开发人员通过该节可以配置
要显示的 html 错误页
以代替错误堆栈跟踪。

<customErrors mode= "RemoteOnly " defaultRedirect= "GenericErrorPage.htm ">
<error statusCode= "403 " redirect= "NoAccess.htm " />
<error statusCode= "404 " redirect= "FileNotFound.htm " />
</customErrors>
-->
</system.web>
------解决方案--------------------
/// <summary>
/// 跳转错误页面
/// </summary>
/// <param name= "Msg "> </param>
public static void Redirect(string Msg)
{
try
{
HttpContext.Current.Response.Redirect(HttpContext.Current.Request.ServerVariables[ "http_host "] + ConfigurationManager.AppSettings[ "BackGroundPath "] + "Err.aspx?ErrMsg= " + Msg.Replace( "\n\r ", " <br> "));
}
catch { }

}