Sergey
Sergey

Reputation: 8091

After upgrading to MVC 4 async tasks don't work

I've upgraded my website to MVC 4 from MVC 3 and started experience this error:

An asynchronous operation cannot be started at this time. Asynchronous operations may only be started within an asynchronous handler or module or during certain events in the Page lifecycle. If this exception occurred while executing a Page, ensure that the Page is marked <%@ Page Async="true" %>

Though it worked in MVC 3.

This code:

            Uri uri = new Uri(string.Format(
            UrlTemplate,
            ServiceId,
            HttpUtility.UrlEncode(id),
            HttpUtility.UrlEncode(org),
            HttpUtility.UrlEncode(user),
            HttpUtility.UrlEncode(activity),
            HttpUtility.UrlEncode(module)));

        using (var client = new WebClient())
        {
            client.DownloadDataTaskAsync(uri);
        }

Upvotes: 1

Views: 932

Answers (1)

Roy Dictus
Roy Dictus

Reputation: 33149

As the error message says: ensure that the Page is marked <%@ Page Async="true" %>. This is a feature new to MVC 4.

Upvotes: 2

Related Questions