我想知道您是否可以禁用Web例外,例如,
404 Not Found
答案 0 :(得分:0)
您不禁用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!
答案 1 :(得分:-1)
这必须在IIS中完成。
要执行此操作,请导航至开始 - >控制面板 - >管理工具 - > IIS
在列表中选择您的Web服务器,然后双击错误页面选项
为您要替换或删除的错误消息添加特定网页。
如果您需要更多详细信息,请参阅以下内容:http://www.braintrove.com/id/46