In another answer roughly the following code was used:
c.Events.OnRedirectToAccessDenied = async (context) => context.Response.StatusCode = 403;
The compiler warns on the arrow operator that the expression is not awaited in any form. Removing the async keyword confirms that OnRedirectToAccessDenied wants a function that returns a Task (Func<RedirectContext<CookieAuthenticationOptions>, Task>) and the following can't build:
c.Events.OnRedirectToAccessDenied = (context) => context.Response.StatusCode = 403;
The async keyword is only used to convert the expression to a task, it seems. I haven't seen async used this way before.
The following code will not give any compiler warnings, but it doesn't look as elegant.
c.Events.OnRedirectToAccessDenied = (context) => Task.Run(
() => context.Response.StatusCode = 403
);
Is the compiler warning unwarranted, and is it a good idea to use async in this manner?
c.Events.OnRedirectToAccessDenied = (ctx) => {ctx.Response.StatusCode = 403; return Task.CompletedTask; }