Click here to Skip to main content
16,018,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Iam Having Error IN My Page The page Throws The Exception.I am Using CustomErrors In WebConfig For Redirecting To Error page.I am Getting Error Message From Exception but It Is Not Redirecting To My Error page..Pls Help Me...


Regards
B.Amuthan
Posted

You have not posted any code.
Below is the code which should be passed as per your requirement.

<customerrors>
       mode="RemoteOnly" 
       defaultRedirect="~/errors/GeneralError.aspx" /></customerrors>




The same you can achieve by adding below code in Global.asax file.
It is simple and self explanatory

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
'GenericError is the page where i am redirecting user with message
        System.Web.HttpContext.Current.Response.Redirect("~/GenericError.aspx")
    End Sub</br></br></br></br>


I normally prefer 2nd option because you get the complete details of errors when required.

Happy Coding

[Edit]Code has been Formatted[Edit]
 
Share this answer
 
v2
Comments
Arun Jacob 7-Jul-10 7:42am    
Please try to format the code properly when you post.
If you are using DefaultRedirect in customerrors section in web.config file and Global.asax file, Application_Error method for error handling. The web.config custom errors will take precedence. If the mode property value is Remoteonly then the client is redirected to error page not the developer if any error occurs. If you as a developer also want to be redirected to the error page please provide mode="On" in custom errors.
 
Share this answer
 
Comments
B.Amuthan 8-Jul-10 1:03am    
Thanks Priya

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