ASP.NET 如何获取 HttpException 错误代码

标签 asp.net httpexception

我正在 try catch 并处理特定的 HttpException,即“远程主机关闭了连接。错误代码是 0x800704CD。”

我的目的是将 HttpException 的 Catch 添加到相关的 Try block 中,并测试生成的错误代码。示例代码:

Try
    // Do some stuff
Catch exHttp As HttpException
    If exHttp.ErrorCode.ToString() = "0x800704CD" Then DoSomething()
Catch ex As Exception
    // Generic error handling
End Try

但我无法弄清楚如何从 HttpException 对象中提取异常中显示的错误代码(即“0x800704CD”)。将 ErrorCode 属性的整数值转换为十六进制会返回“800704CD”,很明显我不明白该代码是如何生成的。

谢谢。

最佳答案

尝试以下代码:

 Try
    // Do some stuff
        Catch exHttp As HttpException
            If exHttp.ErrorCode = &H800704CD Then DoSomething()
        Catch ex As Exception
    // Generic error handling
        End Try

关于ASP.NET 如何获取 HttpException 错误代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13453939/

相关文章:

c# - 类似 Internet Explorer 收藏夹窗口的弹出窗口

c# - 我如何在 ASP.NET 中使用带有图标和格式的 JQuery Datepicker

c# - 在ASP.Net中,同组的单选按钮会自动改变Checked状态吗?

c# - 是什么导致 EF 插入比普通 ADO.NET 慢得多?

asp.net-mvc - 将 View 渲染为字符串,然后重定向会导致异常

ascx 页面中的 javascript 抛出 HTTPException

elasticsearch - 使用 ruflin/elastica 重置索引会在 heroku 上抛出 HttpException

asp.net-mvc - 将 View 呈现为 MVC 中的字符串,然后重定向——解决方法?

css - 如何在 ASP.NET AJAX TabControl 中设置控件样式