【问题标题】:Handle Http Error generically asp.net VB一般处理 Http 错误 asp.net VB
【发布时间】:2014-07-01 11:13:50
【问题描述】:

我是 vb 的新手,我想动态处理 http 错误。发生任何类型的错误都应该重定向到错误页面。我现在在本地服务器上。我已经使用了以下代码,但我需要通用脚本来满足所有 http 错误。

 <httpErrors errorMode="Custom" existingResponse="Replace">
  <remove statusCode="403"  />
  <remove statusCode="404" />
  <remove statusCode="500" />
  <error statusCode="403" path="/Error-404.html" responseMode="Redirect"  />
  <error statusCode="404" path="/Error-404.html" responseMode="Redirect" />
  <error statusCode="500" path="/Error-500.html" responseMode="Redirect" />
</httpErrors>

【问题讨论】:

标签: javascript html asp.net vb.net


【解决方案1】:

您可以捕获 Globals.vb 文件中的所有错误。这个方法:

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
    ' Code that runs when an unhandled error occurs
     HttpContext.Current.Response.Redirect("yourPage")
End Sub

【讨论】:

  • 不,那根本不工作,它显示 IIS 错误 404,我想避免的那些
  • 这个想法是让您编写自己的 aspx 页面并向用户显示友好的消息。使用:HttpContext.Current.Response.Redirect("yourPage.aspx")。您还可以使用 Dim ex As Exception = Server.GetLastError() 来获取引发的异常并将其记录到错误日志中。 Application_Error 方法处理未处理的异常,因此您可能必须删除 Web 配置文件中的 http 条目。
  • 谢谢我找到了另一个解决方案。
【解决方案2】:

我用

Try
...Code Here...
Catch ex As Exception
  Response.Redirect("Error.aspx?ID=" & ex.Message, False)
End Try

我的解决方案中有一个 Error.aspx 页面,用于查询“ID”并将其显示在页面上的标签中。

【讨论】:

    猜你喜欢
    • 2013-05-10
    • 1970-01-01
    • 2013-02-24
    • 2015-02-03
    • 2013-01-16
    • 1970-01-01
    • 2015-04-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多