0

I am new in vb and I want to get http errors handled Dynamically.Any sort of error occurs it should redirect to error page. I am on local server for now. I have used the following code that works fine but i need generic script to cater all http errors.

 <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>
  • Duplicate of [this question](http://stackoverflow.com/questions/15654840/how-to-add-a-default-error-page-using-httperrors?rq=1)? – Grim Jul 01 '14 at 11:57

2 Answers2

0

You can catch all errors in your Globals.vb file. this method:

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
  • No thats not working at all, it shows IIS error-404, the ones that i want to avoid – Sheikh Ozair Bilal Jul 02 '14 at 05:32
  • The idea is for you to write your own aspx page and show the user a friendly message. Use: HttpContext.Current.Response.Redirect("yourPage.aspx"). You can also use Dim ex As Exception = Server.GetLastError() to get the exception thrown and log it to your error log. Application_Error method handles unhandled exceptions so you might have to remove your http entries in the web config file. –  Jul 02 '14 at 22:33
  • Thanks i found out another solution. – Sheikh Ozair Bilal Jul 07 '14 at 05:09
0

I use

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

I have an Error.aspx page in my solution that queries the "ID" and displays it in a label on the page.