我想知道您是否可以禁用Web异常,例如,
404未找到
发布于 2012-04-16 14:23:04
你不能禁用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!发布于 2012-04-16 03:15:24
这必须在IIS中完成。
为此,导航以启动->控制面板->管理工具-> IIS
在列表中选择web服务器,然后双击错误页选项。
为要替换或删除的错误消息添加特定网页。
如果您需要更多的细节,下面是一个很好的介绍:http://www.braintrove.com/id/46
https://stackoverflow.com/questions/10167846
复制相似问题