I've got a couple ASP.Net MVC and WebAPI projects. Most of them are up to date (MVC 5 / WebAPI 2). I've been double-checking my security assumptions since I'm implementing a global filter (for MVC) and a delegating handler (for WebAPI) to unify security across the system.
In that context, I've come across a few articles and posts (see below) which say you should always be setting UseTaskFriendlySynchronizationContext
to true
(it defaults to false
). This seems odd to me as even in VS2013 using MVC 5 and WebAPI 2 new project templates (as well as the ASP.Net WebForms template) do not set this app setting at all.
The MSDN documentation on this setting is practically non-existent and the posts I've found that do say it's required for async programming seem to be in the context of WebForms.
So here are my questions:
Here are some of the articles I've seen regarding UseTaskFriendlySynchronizationContext
:
SynchronizationContext
in ASP.NET by Marcus van HoudtSome articles that really helped me get a grasp on how all this stuff works that never mention UseTaskFriendlySynchronizationContext
:
The missing key reference is this blog post. Specifically, you need to either set UseTaskFriendlySynchronizationContext
or set targetFramework
to 4.5
. Creating a new project sets targetFramework
to 4.5
, so you do get the correct behavior (UseTaskFriendlySynchronizationContext
is implicitly set to true
).
To answer your specific questions:
async
tutorials assume a GUI application scenario.Thread.CurrentPrincipal
after you leave the ASP.NET context.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