Click here to Skip to main content
16,014,662 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
can we handle this issue under Application_Error() in global.asax,
as I displayed HttpUnhandledException type exception on error.aspx page but cant redirect for non HttpUnhandledException exception, so tried to show non HttpUnhandledException exception with Responce.Write() but it seems bad.

here is my code;

XML
protected void Application_Error(object sender, EventArgs e)
        {
            //// Code that runs when an unhandled error occurs
            HttpContext ctx = HttpContext.Current;
            Exception exc = ctx.Server.GetLastError();

            // Log the exception and notify system operators
            Utilities.writeLog(this, exc);
            if (exc is HttpUnhandledException)
            {
                // Pass the error on to the error page.
                // Server.Transfer("ErrorPage.aspx?handler=Application_Error%20-%20Global.asax", true);
                Response.Redirect("~/SITE/Home/ErrorPage.aspx");
            }
            else
            {
                Response.Clear();

                if (null != exc)
                    Response.Write("<h1>" + exc.Message + "</h1>");
                else
                    Response.Write("<h1>" + HttpContext.Current.AllErrors[0].Message.ToString() + "</h1>");
                //Response.Write("<pre>" + exc.ToString() + "</pre>");
            }
            //Get the exception object.

            Server.ClearError();
        }

can we handle this issue under Application_Error() in global.asax,
as I tried to show non HttpUnhandledException exception on Responce.Redirect but it seems bad.s I tried to show non HttpUnhandledException exception on Responce.Redirect but it seems bad.

here is my code;ere is my code;

protected void Application_Error(object sender, EventArgs e)
{
//// Code that runs when an unhandled error occurs
HttpContext ctx = HttpContext.Current;
Exception exc = ctx.Server.GetLastError();

// Log the exception and notify system operators
Utilities.writeLog(this, exc);
if (exc is HttpUnhandledException)
{
// Pass the error on to the error page.
// Server.Transfer("ErrorPage.aspx?handler=Application_Error%20-%20Global.asax", true);
Response.Redirect("~/SITE/Home/ErrorPage.aspx");
}
else
{
Response.Clear();

if (null != exc)
Response.Write("

" + exc.Message + "

");
else
Response.Write("

" + HttpContext.Current.AllErrors[0].Message.ToString() + "

");
//Response.Write("
" + exc.ToString() + "
");
}
//Get the exception object.

Server.ClearError();
}protected void Application_Error(object sender, EventArgs e)
{
//// Code that runs when an unhandled error occurs
HttpContext ctx = HttpContext.Current;
Exception exc = ctx.Server.GetLastError();

// Log the exception and notify system operators
Utilities.writeLog(this, exc);
if (exc is HttpUnhandledException)
{
// Pass the error on to the error page.
// Server.Transfer("ErrorPage.aspx?handler=Application_Error%20-%20Global.asax", true);
Response.Redirect("~/SITE/Home/ErrorPage.aspx");
}
else
{
Response.Clear();

if (null != exc)
Response.Write("

" + exc.Message + "

");
else
Response.Write("

" + HttpContext.Current.AllErrors[0].Message.ToString() + "

");
//Response.Write("
" + exc.ToString() + "
");
}
//Get the exception object.

Server.ClearError();
}
Posted
Comments
durgeshtupkar10 2-Aug-14 1:39am    
Any Help...!!!

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