自定义错误处理页面方法一
添加nfig < systemweb>< /systemweb>中添加< customErrors mode=On
defaultRedirect=ApplicationErroyaspx >< /customErrors>节点
添加错误处理页面ApplicationErroyaspx调用下面的方法
privatevoidDealErroy()
{
HttpExceptionerroy=newHttpException();
stringstrCode=erroyErrorCodeToString();
stringstrMsg=erroyMessage;
erroyHelpLink=sss;
ResponseWrite(ErrorCode:+strCode+<br>);
ResponseWrite(Message:+strMsg+<br>);
ResponseWrite(HelpLink:+erroyHelpLink+<br>);
ResponseWrite(Source:+erroySource+<br>);
ResponseWrite(TargetSite:+erroyTargetSite+<br>);
ResponseWrite(InnerException:+erroyInnerException+<br>);
ResponseWrite(StackTrace:+erroyStackTrace+<br>);
ResponseWrite(GetHtmlErrorMessage:+erroyGetHtmlErrorMessage()+<br>);
ResponseWrite(erroyGetHttpCode()ToString():+erroyGetHttpCode()ToString()+
<br>);
ResponseWrite(erroyDataToString()::+erroyDataToString()+<br>);
}
这种方法不能完整地显示错误信息
自定义错误处理页面方法二
添加nfig < systemweb>< /systemweb>中添加< customErrors mode=On
defaultRedirect=ApplicationErroyaspx >< /customErrors>节点
添加Globalasax文件找到Application_Error事件加入以下代码
Exceptionerroy=ServerGetLastError();
stringerr=出错页面是+RequestUrlToString()+<br>;
err+=异常信息+erroyMessage+<br>;
err+=Source:+erroySource+<br>;
err+=StackTrace:+erroyStackTrace+<br>;
ServerClearError();
Application[erroy]=err;
添加错误处理页面ApplicationErroyaspx 加入以下代码
ResponseWrite(Application[erroy]ToString());
这种方法能完整地显示
错误信息
最好的办法还是两种方法一起用最好!
另:nfig中也可以把
<errorstatusCode=redirect=/>//访问被禁止
<errorstatusCode=redirect=/>//找不到页面
添加进去
http错误代码含义
: Continue
: witching Protocols
: OK
: Created
: Accepted
: NonAuthoritative Information
: No Content
: Reset Content
: Partial Content
: Multiple Choices
: Moved Permanently
: Found
: See Other
: Not Modified
: Use Proxy
: Temporary Redirect
: Bad Request
: Unauthorized
: Pay
: Forbidden
: Not Found
: Method Not Allowed
: Not Acceptable
: Proxy Authentication Required
: Request Timeout
: Conflict
: Gone
: Length Required
: Precondition Failed
: Request Entity Too Large
: RequestURI Too Large
: Unsupported Media Type
: Requested range not satisfiable
: Expectation Failed
: Internal Server Error
: Not Implemented
: Bad Gateway
: Service Unavailable
: Gateway Timeout
: HTTP Version not supported
以上就是自定义错误处理页面的添加方法