Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.Net Response.Redirect not working in Application_Error?

I don't know why the Response.Redirect not working properly when I deploy my code to IIS7? The white/yellow error page always get displayed instead of my Errors.aspx. But when debug running using Visual Studio on my computer, it runs just fine?

protected void Application_Error(object sender, EventArgs e)
        {
            ILog log = LogManager.GetLogger(typeof(Global).Name);
            Exception objErr = Server.GetLastError().GetBaseException();
            log.Error(objErr);
            string err = "Error Caught in Application_Error event\n" +
                    "\nError Message:" + objErr.Message.ToString() +
                    "\nStack Trace:" + objErr.StackTrace.ToString();
            EventLog.WriteEntry("Kiosk", err, EventLogEntryType.Error);
            Server.ClearError();
            Response.Redirect("~/Error.aspx", false);
        }
like image 862
Leo Avatar asked Dec 14 '10 03:12

Leo


2 Answers

I had the same problem and solved it with:

HttpContext.Current.ClearError();             
Response.Redirect("~/Error.aspx", false);
return;
like image 76
Christian van R Avatar answered Oct 16 '22 23:10

Christian van R


HttpContext.Current.Server.ClearError();
HttpContext.Current.ClearError();
====================================================================
Redirect to NEW VIRTUAL! directory (Error)
HttpContext.Current.Response.Redirect([http://localhost:8990/Error/ErrorPageServer.aspx]);
like image 4
jeka Avatar answered Oct 16 '22 23:10

jeka