Click here to Skip to main content
15,885,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a page as mycustompage.htm and ErrorPage.htm for custom errors.

In web config I have code like this:
XML
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm">
    <error statusCode="404" redirect="ErrorPage.htm" />
  </customErrors>


If error arises I want to display in mycustompage.htm or ErrorPage.htm.
Please let me know how to do it?

Thanking You
Mohammad Wasif
Posted
Updated 12-Jan-11 21:36pm
v3
Comments
Dalek Dave 13-Jan-11 3:36am    
Edited for Readability.

Solution given by Hiren is Good.

You can also achieve the same using Global.asax.

VB
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
         '' Code that runs when an unhandled error occurs
        Dim ctx As HttpContext = HttpContext.Current
        Dim exception As Exception = ctx.Server.GetLastError

        Dim errInfo As String = "<br>Error In : " & ctx.Request.Url.ToString() & _
        "<br>Source:" & exception.Source & _
        "<br>Message: " & exception.Message
        '"<br>Stack Trace: " & exception.StackTrace
        ctx.Response.Write(errInfo)
        'To let the page finish running we clear the error
        ctx.Server.ClearError()
        Session("value") = errInfo
        System.Web.HttpContext.Current.Response.Redirect("~/ErrorPage.aspx")
    End Sub


Regards
 
Share this answer
 
Comments
Dalek Dave 13-Jan-11 3:36am    
Good Answer.
It's just a simple, See THIS[^] article.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900