自定義錯誤處理頁面方法一
添加nfig < systemweb>< /systemweb>中添加< customErrors mode=On
defaultRedirect=ApplicationErroyaspx >< /customErrors>節點
添加錯誤處理頁面ApplicationErroyaspx調用下面的方法
private void DealErroy()
{
HttpException erroy = new HttpException();
string strCode = erroyErrorCodeToString();
string strMsg = 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事件加入以下代碼
Exception erroy = ServerGetLastError();
string err = 出錯頁面是 + RequestUrlToString() + < br>;
err += 異常信息 + erroyMessage + < br>;
err += Source: + erroySource + < br>;
err += StackTrace: + erroyStackTrace + < br>;
ServerClearError();
Application[erroy] = err;
添加錯誤處理頁面ApplicationErroyaspx 加入以下代碼
ResponseWrite(Application[erroy]ToString());
這種方法能完整地顯示
錯誤信息
最好的辦法還是兩種方法一起用最好!
另:nfig中也可以把
< error statusCode= redirect= />//訪問被禁止
< error statusCode= 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
以上就是自定義錯誤處理頁面的添加方法
From:http://tw.wingwit.com/Article/program/net/201311/11669.html