[英]An asynchronous operation cannot be started at this time Exception occurs on calling WebService?
In my ASP.NET MVC 3 project I'm calling a web service for login authentication.在我的 ASP.NET MVC 3 项目中,我正在调用 Web 服务进行登录身份验证。 But it throws an exception:但它抛出一个异常:
Exception Details:异常详情:
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" %>.如果在执行 Page 时发生此异常,请确保将 Page 标记为 <%@ Page Async="true" %>。
How to fix this issue?如何解决这个问题?
Make sure that your Controller method returns an async Task.确保您的 Controller 方法返回一个异步任务。
public class ServiceController : Controller
{
public async Task<ActionResult> Index()
{
var service = new Service();
await service.CallMethodAsync();
return View();
}
}
Basically, the documentation is written in a way where they believe you are only using ASP.NET WebForms, however obviously you can use this in MVC applications too, so their documentation needs to be updated.基本上,文档的编写方式他们认为您只使用 ASP.NET WebForms,但显然您也可以在 MVC 应用程序中使用它,因此他们的文档需要更新。
您正在调用 ASYNC 方法,因此您必须在页面声明 <%@ Page .....%> 中添加 Async="true"。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.