While doing some asynchronous coding in a code behind file, I ran across a System.InvalidOperationException exception, with this message:
Asynchronous operations are not allowed in this context. Page starting an asynchronous operation has to have the Async attribute set to true and an asynchronous operation can only be started on a page prior to PreRenderComplete event.
Luckily, the solution was very easy. I added the tag Async=”true” to the Page declaration, and that was it:
<%@ Page Language="C#" Async="true" ... %>