我希望在C#中的Page_Load之后调用Page_Error方法,以防出现错误。我正在测试它的情况或错误但异常没有显示任何值。有什么想法吗?
private void Page_Error(object sender, EventArgs e)
{
Response.Write("OK");
Response.End();
Exception objError = Server.GetLastError().GetBaseException();
string strError = "<b>Error Has Been Caught in Page_Error event</b><hr><br>" +
"<br><b>Error in: </b>" + Request.Url.ToString() +
"<br><b>Error Message: </b>" + objError.Message.ToString()+
"<br><b>Stack Trace:</b><br>" +
objError.StackTrace.ToString();
Response.Write(strError.ToString());
}
答案 0 :(得分:0)
你在错误的地方使用Response.End(),这应该会在屏幕上显示错误
Response.Write("OK");
Exception objError = Server.GetLastError().GetBaseException();
string strError = "<b>Error Has Been Caught in Page_Error event</b><hr><br>" +
"<br><b>Error in: </b>" + Request.Url.ToString() +
"<br><b>Error Message: </b>" + objError.Message.ToString() +
"<br><b>Stack Trace:</b><br>" +
objError.StackTrace.ToString();
Response.Write(strError.ToString());
Response.End();