コード例 #1
0
 protected override void Redirect(ActionExecutedContext filterContext)
 {
     PlaceInItemDictionary("Error", filterContext.Exception, filterContext);
     PlaceInItemDictionary("Controller", filterContext.ActionDescriptor.ControllerDescriptor.ControllerName, filterContext);
     PlaceInItemDictionary("Action", filterContext.ActionDescriptor.ActionName, filterContext);
     filterContext.ExceptionHandled = true;
     //filterContext.HttpContext.Server.Transfer(Url, true);
     var transferResult = new TransferResult(Url);
     transferResult.ExecuteResult(filterContext.Controller.ControllerContext);
 }
コード例 #2
0
        protected override void Redirect(ActionExecutedContext filterContext)
        {
            //Turn "Foo.Foo.Foo.BarController" into "Bar"
            string controllerName = Controller.ToString();
            controllerName = controllerName.Substring(controllerName.LastIndexOf(".") + 1);
            controllerName = controllerName.Substring(0, controllerName.LastIndexOf("Controller"));

            //turn route identity into url
            RouteValueDictionary rvd = new RouteValueDictionary(
                new
                {
                    controller = controllerName,
                    action = Action
                });

            ControllerContext ctx = new ControllerContext(
                filterContext.HttpContext,
                filterContext.RouteData,
                filterContext.Controller
                );

            VirtualPathData vpd = RouteTable.Routes.GetVirtualPath(ctx.RequestContext, rvd);
            string url = vpd.VirtualPath;

            //Redirect
            PlaceInItemDictionary("Error", filterContext.Exception, filterContext);
            PlaceInItemDictionary("Controller", filterContext.ActionDescriptor.ControllerDescriptor.ControllerName, filterContext);
            PlaceInItemDictionary("Action", filterContext.ActionDescriptor.ActionName, filterContext);

            filterContext.ExceptionHandled = true;
            var transferResult = new TransferResult(url);
            transferResult.ExecuteResult(filterContext.Controller.ControllerContext);
            //filterContext.HttpContext.Server.Transfer( url, true );
        }