日期:2014-05-18  浏览次数:20385 次

|M| 如何在错误网页显示错误信息
<customErrors   mode= "On "     defaultRedirect= "/web/error/Error.aspx ">          
        </customErrors>

http://localhost:1215/web/error/Error.aspx?aspxerrorpath=/web/Defaudlt.aspx

像上面我可以用Request来得到出错页面
但如果在这个页面显示出错信息

谢谢


------解决方案--------------------
有一种做法是,自己写个页面基类继承与System.Web.UI.Page

然后让所有的页面继承与此页面基类

然后在页面基类的Page_Error事件中写

protected void WishPage_Error(object sender, System.EventArgs e)
{
string errMsg;
Exception currentError = Server.GetLastError();

errMsg = " <link rel=\ "stylesheet\ " href=\ "/Wish/Styles/Wish.CSS\ "> ";
errMsg += " <h1> 页面错误 </h1> <hr/> 你访问的页面出错...br/> "+
"错误位于: "+Request.Url.ToString()+ " <br/> "+
"错误信息: <font class=\ "ErrorMessage\ "> "+ currentError.Message.ToString() + " </font> <hr/> "+
" <b> 堆栈跟踪: </b> <br/> "+
currentError.ToString();

if ( !(currentError is AppException) )
{
//写入日志
LogEvent( currentError.ToString(), EventLogEntryType.Error );
}

Response.Write( errMsg );
Server.ClearError();
}
------解决方案--------------------
或者利用httpmodule来做.
------解决方案--------------------
可以直接在Global.asax.cs文件里的
protected void Application_Error(Object sender, EventArgs e)
{
Response.Redirect(string.Format( "Error.aspx?msg={0}&url={1} ",Server.GetLastError().GetBaseException().Message.ToString(),Request.Url));


}