In my ASP.NET MVC 3 project I'm calling a web service for login authentication. 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" %>.
How to fix this issue?
Make sure that 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 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.
You are calling an ASYNC method therefore you must add Async="true" inside your page declaration <%@ Page .....%>.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With