我想知道您是否可以禁用 Web 异常,例如,
404 未找到
您没有禁用 WebExceptions。像大多数其他例外一样,它们的全部意义在于表明一个在发生时无法修复的问题。您不能忽略这一点并期望您的应用程序能够正常工作。
您所做的是捕获并处理异常。像这样。
Try
Dim response = request.GetResponse()
'... do stuff with response here ...
Catch ex as WebException
' Note, `response` probably isn't usable here! Pretty sure it's
' out of scope. In any case, if `GetResponse` is throwing the
' exception, then it didn't return a value. However, you should be
' able to access `ex.Response` to get info about the response,
' including the HTTP response code.
Dim errorResponse = CType(ex.Response, HttpWebResponse)
If errorResponse.StatusCode = HttpStatusCode.NotFound Then
'... handle error ...
Else
' if it's not a 404, we're not doing anything about the exception
' so rethrow it
Throw
End If
End Try
' Note, `response` is out of scope here!
这必须在 IIS 中完成。
为此,导航至开始 -> 控制面板 -> 管理工具 -> IIS
在列表中选择您的 Web 服务器并双击错误页面选项
为您尝试替换或删除的错误消息添加特定网页。
如果您需要更多详细信息,这是一个很好的演练:http ://www.braintrove.com/id/46