当服务器关闭时,我必须呈现一个简单的视图。有一个检查服务器连接的全局过滤器。在过滤器内部,应执行重定向以显示服务器在时的视图。问题是重定向到控制器永远不会发生。过滤器内的代码执行了几次,然后我在浏览器中收到太多请求错误。如果我重定向到图像或文本一切正常。但是渲染视图是不行的。
全局过滤器:
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
using (var connection = new SqlConnection ConfigurationManager.ConnectionStrings["IncbbsConnection"].ToString()))
{
try
{ connection.Open(); }
catch (SqlException)
{
// This works, the text shows:
//var content = new ContentResult {Content = "Server down!", ContentType = "text/plain"};
// filterContext.Result = content;
// This works, the image appears:
//filterContext.Result = new RedirectResult("~/Content/images/LoginLogo1.png");
// doesn't perform redirect to a controller
filterContext.Result = new RedirectToRouteResult("ServerDown",new RouteValueDictionary(new controller = "Error", action = "ServerDownView"}));
}
finally
{ connection.Close(); }
}
}