I’m trying to handle 404 error under IIS (and Azure) but the code below does not work.
On the localhost this works well.
What should I do to fix this problem?
from httpmodule
protected void Application_Error(Object source, EventArgs e)
{
HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;
Exception ex = application.Server.GetLastError().GetBaseException();
if (ex != null && ex is HttpException)
{
var httpEx = ex as HttpException;
if (httpEx != null && httpEx.GetHttpCode() == 404)
{
context.Response.StatusCode = 404;
application.Response.Redirect(BXSite.Current.GetUrl("/404/"));
application.Server.ClearError();
}
}
}
I just added “false” to the second parameter of Redirect function and redirect began works right.
Like this:
application.Response.Redirect(“/404/”,false).