We recently upgraded our code base from .Net 4.0 to .Net 4.5.1 and from MVC 2.0 to MVC 5.2.2.
We have our own method in our base controller class, which allows us to update several parts of our views within a single request. Starting with the update, this no longer works.
Original code:
protected void IncludeAction(string actionName, string controllerName, object routeValues) {
We get errors when calling httpHandler.ProcessRequest . We have used this technique in many places. After long searches, it seemed like Server.TransferRequest should be used Server.TransferRequest .
New code
protected void IncludeAction(string actionName, string controllerName, object routeValues) {
When called from this code:
IncludeAction("OptInBanner", "Person"); IncludeAction("NavMenu", "Person"); return Transfer(returnurl);
Our new code generates this error:
Type: System.InvalidOperationException Message: TransferRequest cannot be invoked more than once. Stack Trace: at System.Web.HttpServerUtility.TransferRequest(String path, Boolean preserveForm) at MyProject.MyNamspace.MyBaseController.IncludeAction(String actionName, String controllerName, Object routeValues) at MyProject.MyNamspace.MyBaseController.IncludeAction(String actionName, String controllerName) at MyProject.MyNamspace.MyController.MyAction(Boolean myChoice, String returnurl) at .lambda_method(Closure , ControllerBase , Object[] )
Since the message clearly says that I cannot call TransferRequest more than once, but my code must perform two controller actions in addition to redirecting and performing the third action, I thought I would return to the old code. However, this generates this error:
Type: System.InvalidOperationException Message: 'HttpContext.SetSessionStateBehavior' can only be invoked before 'HttpApplication.AcquireRequestState' event is raised. Stack Trace: at System.Web.Routing.UrlRoutingHandler.ProcessRequest(HttpContextBase httpContext) at MyProject.MyNamspace.MyBaseController.IncludeAction(String actionName, String controllerName, Object routeValues) at MyProject.MyNamspace.MyBaseController.IncludeAction(String actionName, String controllerName) at MyProject.MyNamspace.MyController.MyAction(Boolean myChoice, String returnurl) at .lambda_method(Closure , ControllerBase , Object[] )
For this function, how can I keep the original behavior without the errors that we had in .Net 4.0 and MVC 2.0 when using the newer structure and MVC?