+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Does Sitefinity support async MVC actions?

Does Sitefinity support async MVC actions?

8 posts, 1 answered
  1. RJ Cuthbertson
    RJ Cuthbertson avatar
    41 posts
    Registered:
    01 Jun 2015
    27 Jul 2015
    Link to this post

    Recently, I tried to use an async action on an MVC controller in Sitefinity and was greeted with the error message:

    "The asynchronous action method 'IndexAsync' returns a Task, which cannot be executed synchronously."

     

    This was in Sitefinity 8.0. Async actions have been supported in MVC since MVC 4.0 (which is the version leveraged by Sitefinity 8.0). See Using Asynchronous Methods in ASP.NET MVC 4 for more information regarding this.

     

    Does Sitefinity support async MVC actions? / Am I missing a setting allowing this?

     If not, when will Sitefinity support this?

     

    Thank you,

    RJ Cuthbertson

     

    For reference, I am using the following temporary workaround right now:

    [AcceptVerbs(HttpVerbs.Get)]
    public ActionResult Index()
    {
        return IndexAsync().Result;
    }
     
    [NonAction]
    private async Task<ActionResult> IndexAsync()...

    Answered
  2. Simon
    Simon avatar
    3 posts
    Registered:
    31 Jul 2014
    30 Jul 2015
    Link to this post

    Hey Telerik,

     I'd like to know this as well. 

  3. RJ Cuthbertson
    RJ Cuthbertson avatar
    41 posts
    Registered:
    01 Jun 2015
    30 Jul 2015
    Link to this post

    The async creep is only going to expand further in my project as we're using an external ASP.NET Identity based solution which heavily uses the ​Task-based Asynchronous ​Pattern. Aside from that, we're using HttpClient for ​server-to-server web requests to communicate between various 3rd-party systems.

     

    And I'd really like to not have to wrap every controller action with a synchronous, blocking version relying on .Result ...

  4. Nikola Zagorchev
    Nikola Zagorchev avatar
    424 posts
    Registered:
    29 Sep 2016
    30 Jul 2015
    Link to this post
    Hello,

    Using the controller in classic MVC will allow you to use async Actions. You can register your own route in Sitefinity 8.1 the following way:
    protected void Application_Start(object sender, EventArgs e)
            {
                Bootstrapper.Initialized += new EventHandler<ExecutedEventArgs>(Bootstrapper_Initialized);
            }
      
            protected void Bootstrapper_Initialized(object sender, ExecutedEventArgs e)
            {
                if (e.CommandName == "RegisterRoutes")
                {
                    RouteTable.Routes.MapRoute(
                        "Classic",
                        "customprefix/{controller}/{action}/{id}",
                        new { controller = "MyController", action = "Index", id = (string)null }
                    );
                }
            }

    This way you can use the async controller actions freely. They will be handled as in a normal web application.
    However, if you use the async Action in a widget, you will indeed get the InvalidOperationException. Currently, we do not support rendering and using MVC Widgets async Actions on both hybrid and pure pages. As you can see from the StackTrace of the error:
    at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
    The ControllerActionInvoker is used rather than the AsyncControllerActionInvoker. You can also observe from the external code while in debugging in VS that the async invoker is called when serving the Action under classic mode when it works correctly.

    Hope this info is useful.

    Regards,
    Nikola Zagorchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  5. RJ Cuthbertson
    RJ Cuthbertson avatar
    41 posts
    Registered:
    01 Jun 2015
    30 Jul 2015
    Link to this post
    Will asynchronous actions be supported in the future in Hybrid or Pure modes?
  6. Nikola Zagorchev
    Nikola Zagorchev avatar
    424 posts
    Registered:
    29 Sep 2016
    04 Aug 2015
    Link to this post
    Hi,

    Unfortunately, currently this has not been discussed, so it is not in the set plans for the upcoming releases. We are now focused on improving the Feather and providing out of the box functionality for the built in web forms widgets and modules. However, it also depends on the business scenario and desirability of this feature. I have logged a feature request about this in our portal and you can review it on the bellow link:
    http://feedback.telerik.com/Project/153/Feedback/Details/165662-mvc-ability-to-use-async-actions-in-mvc-widgets

    Regards,
    Nikola Zagorchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  7. RJ Cuthbertson
    RJ Cuthbertson avatar
    41 posts
    Registered:
    01 Jun 2015
    04 Aug 2015 in reply to Nikola Zagorchev
    Link to this post
    Thank you for creating that.
  8. Nikola Zagorchev
    Nikola Zagorchev avatar
    424 posts
    Registered:
    29 Sep 2016
    07 Aug 2015
    Link to this post
    Hi,

    Please, vote for the item and follow its status.
    Thank you all.

    Regards,
    Nikola Zagorchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
8 posts, 1 answered