我已将我的网站从MVC 3升级到MVC 4并开始遇到此错误:
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" %>
虽然它在MVC 3中有效。
此代码:
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);
}
答案 0 :(得分:2)
正如错误消息所示:确保将页面标记为<%@ Page Async="true" %>
。这是MVC 4的新功能。