【发布时间】:2018-01-09 09:07:11
【问题描述】:
在我的要求中,我返回了自定义错误。 global.asax 应用程序错误未重定向任何其他 URL。 Response.Redirect(URL),Server.Transfer(URL) 没有重定向。它显示发送 HTTP 标头后无法重定向。我试过但没有工作。请尝试帮助我。下面是我的代码
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);
}
【问题讨论】:
-
这是 MVC(来自您的问题标签)吗?如果是,请尝试 Context.Response.Redirect()
-
我已经尝试过 HttpContext.Current.Response.Redirect(URL)。 @Surjit SD
标签: c# asp.net asp.net-mvc-4 global-asax