此时无法启动异步操作。异步操作只能在异步处理程序或模块中启动,或者在页面生命周期中的某些事件中启动。如果在执行页面时发生此异常,请确保将页面标记为<%@ Page Async =“true”%>方法
每次异步调用都失败,包括我的发送邮件异步操作方法
mailSmtpClient.SendAsync(mailMessage, userState);
我尝试过将我的webconfig更改为如下所示的概念:
<appSettings>
<add key="aspnet:AllowAsyncDuringSyncStages" value="false" />
</appSettings>
我也试过
Task.Factory.StartNew(() => bw.RunWorkerAsync());
当我尝试第二次时,它刷新了我的HttpContext并获得了一个HttpContext异常
我的代码是基本的后台工作者
public void startsending() {
//Task.Factory.StartNew(() => bw.RunWorkerAsync()); fails
bw.RunWorkerAsync();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.Flush(); // send all buffered output to client
HttpContext.Current.Response.End();
}
答案 0 :(得分:0)
设置aspnet:AllowAsyncDuringSyncStages默认为false。尝试将其设置为true。