How to access RequestModel while using a custom controller (site.axd)?

Using a “custom controller” accessed through the site.axd route the Litium.Accelerator.Mvc.Routing.RequestModelHandler.AccessorCleanup.Dispose() method is called before Litium.Accelerator.Mvc.Routing.RequestModelActionFilter.OnActionExecuting() is called which means that RouteRequestLookupInfoAccessor.RouteRequestLookupInfo is null and we don’t get the RequestModel.

What are we doing wrong?

Litium version: 7.1

Litium.Accelerator.Mvc.Routing.RequestModelHandler is used for api controllers request and will only be used if the litium-request-context http header is included with the request.

Litium.Accelerator.Mvc.Routing.RequestModelActionFilter is used for mvc controllers.

If you get the Litium.Accelerator.Mvc.Routing.RequestModelHandler.AccessorCleanup.Dispose() to be executed when you executing an mvc controller you are passing in the litium-request-context http header with the request that will make both of them to execute.

If you need to pass the request context into the mvc controller you should probably change to use another name of the http header to not get conflicts between them.

How do I avoid the Dispose() to run before the action? I’m also trying to call an custom mvc-method. Shouldn’t I use the litium-request-context header?

I think the problem you are getting is that you returning an IEnumerable<> that is only a placeholder and not populated before later when it is used; after the Dispose have been executed. Instead you should return an IList<> or other populated object from the controller

I’m returning a ActionResult and a CategoryPageViewModel as View(model). Is there any difference if the method is GET or POST? I’m using POST to my method now.

What properties do you have on your model ?

GET and POST should behave the same.

The properties are the same as in vanilla accelerator.

This model is used for the web-api endpoints. If you want to build the same to use for an mvc controller you need to change the name and replicate the logic in an action filter, like the Litium.Accelerator.Mvc.Routing.RequestModelActionFilter but reading the data from the header instead.

The model is used in the Index method on the CategoryController and it’s a mvc controller. And I have made a simple action that is returning a partialView in the same controller. Still my problem is that the dispose gets hit before the method. What is the result of not running the registerForDispose on a certain request? I’m thinking of checking if a certain header is present and skip the registerForDispose then

If the object not is disposed as they should they can cause an memory leak, this depend on the objects that are used on how garbage collection can handle and clean it up.