An asynchronous operation cannot be started at this time. An exception occurs when calling WebService?

In my ASP.NET MVC 3 project, I call a web service to authenticate login. But this throws an exception:

Asynchronous exception

Exception Details:

An asynchronous operation cannot be started at this time. Asynchronous operations can only be started in an asynchronous handler or module, or during certain events in the page life cycle. If this exception occurred while the page was running, make sure the page is marked <% @Page Async = "true"%>.

How to fix this problem?

+10
source share
2 answers

Make sure your controller method returns an async task.

public class ServiceController : Controller { public async Task<ActionResult> Index() { var service = new Service(); await service.CallMethodAsync(); return View(); } } 

Basically, the documentation is written in such a way that, in their opinion, you use only ASP.NET WebForms, however, obviously, you can use this in MVC applications too, therefore their documentation should be updated.

+9
source

You call the ASYNC method, so you need to add Async = "true" to the page declaration & lt;% @Page .....%>.

0
source

Source: https://habr.com/ru/post/947273/


All Articles