In my requirement i am returning custom error. in global.asax application error is not redirecting any other URL. Response.Redirect(URL)
,Server.Transfer(URL)
is not redirecting. it show Cannot redirect after HTTP headers have been sent. i tried but not working. please try to help me.below is my code
try
{
Exception exc = Server.GetLastError();
ErrorLogger LogError = new ErrorLogger();
// Handle HTTP errors
if (exc.GetType() == typeof(HttpException))
{
ex = (HttpException)Server.GetLastError();
int httpCode = ex.GetHttpCode();
// Filter for Error Codes and set text
if (httpCode >= 400 && httpCode < 500)
ex = new HttpException
(httpCode, "Safe message for " + httpCode + " HTTP codes.", ex);
else if (httpCode > 499)
ex = new HttpException
(ex.ErrorCode, "Safe message for " + httpCode + " HTTP codes.", ex);
else
ex = new HttpException
(httpCode, "Safe message for unexpected HTTP codes.", ex);
// Log the exception and notify system operators
ErrorLogger.Error(ex);
Server.ClearError();
Response.Clear();
Response.Buffer = true;
Response.Redirect("http://www.stackoverflow.com");
if (!Response.IsRequestBeingRedirected)
// Will not be called
Response.Redirect("http://www.google.com");
//ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "window.open('ErrorPage.aspx');", true);
//Response.Write("<script> window.open('http://localhost:54749/ErrorPage.aspx','_blank'); </script>");
//Response.Redirect("http://www.google.com", true);
//Response.Redirect("~/ErrorPage.aspx");
}
else
{
ErrorLogger.Error(exc);
// LogError.NotifySystemOps(exc);
// Clear the error from the server
//Server.ClearError();
}
}
catch (Exception ex)
{
ErrorLogger.Error(ex);
}