"The child’s actions are not allowed to perform redirection actions"

I have this error:

Error executing a child request for the 'System.Web.Mvc.HttpHandlerUtil + ServerExecuteHttpHandlerAsyncWrapper' handler.

with internal exception:

The child’s actions are not allowed to perform redirection actions.

Any idea why this is happening?

By the way, an error occurs on this line:

@Html.Action("Menu", "Navigation") 

The menu action in the navigation controller is as follows:

 public ActionResult Menu() { return PartialView(); } 
+8
c # asp.net-mvc-3
source share
4 answers

This is unacceptable since MVC has already launched rendering the view to the browser (client). Thus, MVC Frameworks blocks this because the client is already receiving data (html). While rendering is in progress, you cannot redirect your child view.

Instead, you can return a RedirectToAction .

+5
source share

This happened to me because I had [RequireHttps] on the controller, and the child action is called from another controller. RequireHttps attribute caused redirection

+9
source share

Instead

 @Html.Action("Menu", "Navigation") 

Using

 @Url.Action("Menu", "Navigation") 

Worked for me :)

+5
source share

I had the same situation as described by Doug

My solution: 1) Factory user controller created. This is necessary to get the ControllerContext in my https user attribute.

 public class CustomControllerFactory : DefaultControllerFactory { public override IController CreateController(RequestContext requestContext, string controllerName) { var controller = base.CreateController(requestContext, controllerName); HttpContext.Current.Items["controllerInstance"] = controller; return controller; } } } 

2) The following is written in the Application_Start function from the Global.asax file:

 ControllerBuilder.Current.SetControllerFactory(new CustomControllerFactory()); 

3) Defined user attribute https:

 public class CustomRequireHttpsAttribute : System.Web.Mvc.RequireHttpsAttribute { public bool RequireSecure = false; public override void OnAuthorization(System.Web.Mvc.AuthorizationContext filterContext) { if (RequireSecure && !((Controller)HttpContext.Current.Items["controllerInstance"]).ControllerContext.IsChildAction) { base.OnAuthorization(filterContext); } } } 

4) Using the new attribute to define the account controller: [CustomRequireHttps]

+1
source share

All Articles