Implementing an async custom controller in Umbraco 7
I'm using Umbraco 7.2.5 and I have a very simple custom controller with a single Index() action but as soon as I attempt to make it async, it only ever renders the following:
public virtual async Task<ActionResult> Index(RenderModel model, ProgressModel progressModel)
{
await Task.Run(() =>
{
// Do work here
});
...
return CurrentTemplate(viewModel);
}
To clarify, I'm using the hybrid framework approach where each controller inherits from as base conttroller:
public abstract partial class BaseSurfaceController
: SurfaceController, IRenderMvcController
{
...
}
I've done a lot of reading round and found references to there being a difference between .Net 4 and .Net 4.5 but I've checked and the website is definitely using .Net 4.5
I have also seen this link and implemented the suggested fix but with no luck:
I should add that I have implemented an async SurfaceController in the same project and this works fine, so I'm assuming that it's an issue with IRenderMvcController possibly?
Yeah, I saw that and have tried them with no luck. But it's also a year old and the issue Shazwazza refers to has been closed and should have been implemented in Umbraco since 7.1.5
Have you ever had this issue? You must have implemented an async custom controller at some point.
Hmmmmm, odd. I've done some Async stuff, but not Umbraco Controllers though. I'll ask around the office and see if any of the guys here have tried this.
I discovered why this wasn't working and it was/is the way Umbraco handles actions in it's RenderActionInvoker class. I've outlined the cause and solutions in these articles: part 1 and part 2.
But in a nutshell the easiest fix is to target the template by naming the action the same as the template alias. Otherwise you need to register your own controller factory, which is easy enough and detailed in the articles.
I'm pretty sure that the latest versions of Umbraco handle async actions in the same way that native MVC does as the controller factory/action invoker gubbins was all simplified to use the underlying MVC logic. So hijacked routes and webapi controllers should handle async fine. However, child actions cannot be async as this isn't possible in MVC anyway (AFAIK).
Implementing an async custom controller in Umbraco 7
I'm using Umbraco 7.2.5 and I have a very simple custom controller with a single
Index()
action but as soon as I attempt to make it async, it only ever renders the following:and not the intended view.
To clarify, I'm using the hybrid framework approach where each controller inherits from as base conttroller:
I've done a lot of reading round and found references to there being a difference between .Net 4 and .Net 4.5 but I've checked and the website is definitely using .Net 4.5
I have also seen this link and implemented the suggested fix but with no luck:
https://our.umbraco.org/forum/ourumb-dev-forum/bugs/49922-Umbraco-v7-async-controller-action
I should add that I have implemented an async SurfaceController in the same project and this works fine, so I'm assuming that it's an issue with
IRenderMvcController
possibly?Any help would be appreciated.
Here's a very detailed thread about this on Stack Overflow along with some work arounds :)
Yeah, I saw that and have tried them with no luck. But it's also a year old and the issue Shazwazza refers to has been closed and should have been implemented in Umbraco since 7.1.5
Have you ever had this issue? You must have implemented an async custom controller at some point.
Shawazza's fix from that post has been implemented here: https://github.com/umbraco/Umbraco-CMS/blob/7c4a189aa3cf583954defd9c43a3e55e325f2c3f/src/Umbraco.Web/Mvc/RenderActionInvoker.cs
Hmmmmm, odd. I've done some Async stuff, but not Umbraco Controllers though. I'll ask around the office and see if any of the guys here have tried this.
Any news on this issue, because i am running into the same issue.
In my situation i want to call an action using ajax to create a log record when a user does some actions on the page.
Hi @Bunnynut, what you want to do will work fine because you can use a surface controller to handle the submit and these handle async operations fine.
I discovered why this wasn't working and it was/is the way Umbraco handles actions in it's
RenderActionInvoker
class. I've outlined the cause and solutions in these articles: part 1 and part 2.But in a nutshell the easiest fix is to target the template by naming the action the same as the template alias. Otherwise you need to register your own controller factory, which is easy enough and detailed in the articles.
Hey, is there any final solution to this? As I can figure out the PR with implementing a separate is canceled.
So what do we have to do to be capable of using async within Umbraco in
Thanks a lot!
I'm pretty sure that the latest versions of Umbraco handle async actions in the same way that native MVC does as the controller factory/action invoker gubbins was all simplified to use the underlying MVC logic. So hijacked routes and webapi controllers should handle async fine. However, child actions cannot be async as this isn't possible in MVC anyway (AFAIK).
is working on a reply...