首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >你能禁用网络异常吗?

你能禁用网络异常吗?
EN

Stack Overflow用户
提问于 2012-04-16 01:47:01
回答 2查看 143关注 0票数 0

我想知道您是否可以禁用Web异常,例如,

404未找到

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-04-16 14:23:04

你不能禁用WebExceptions。与大多数其他例外一样,它们的全部目的是发出一个问题在发生时无法解决的信号。你不能忽视这一点,指望你的应用程序能正常工作。

您所做的就是捕捉并处理异常。就像这样。

代码语言:javascript
复制
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!
票数 0
EN

Stack Overflow用户

发布于 2012-04-16 03:15:24

这必须在IIS中完成。

为此,导航以启动->控制面板->管理工具-> IIS

在列表中选择web服务器,然后双击错误页选项。

为要替换或删除的错误消息添加特定网页。

如果您需要更多的细节,下面是一个很好的介绍:http://www.braintrove.com/id/46

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10167846

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档