My MVC4 application was re-factored to introduce some asynchronous code. However, there are several .ascx and .aspx files that are invocation asynchronous methods. For example,
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<SomeModel>" %>
<div id="connection-config-settings">
<%
var authorizationContext = this.AuthorizationContext();
if (await authorizationContext.ConfigurationAuthorization.CanUserUpdateConfig())
{
%>
<pre>The user can update configuration</pre>
<% }
else
{
%>
<pre>The user can NOT update configuration</pre>
<%
}
%>
</div>
Not surprisingly I am getting an error saying that await can only be used inside of a method marked with 'async'. I really do not want to block the async call by using GetAwaiter().GetResult() or .Result or those other hacks. I have been reading a lot about best practices for async programming and the following two resources strongly suggest to never block an async call.
How to call asynchronous method from synchronous method in C#?
https://blog.stephencleary.com/2012/07/dont-block-on-async-code.html
How can I call the async method from my .ascx file?