Async programming has become ubiquitous and the standard tool for making async HTTP requests with C# is
HttpClient from the
System.Net.Http namespace. Examples are aplenty, but good examples are few and far between. Because
IDisposable we are conditioned to new it up in a using statement, make the call and get out as fast as possible.
This is WRONG.
This blog post will pull together advice from the few good resources online that touch on various aspects of why you are using it wrong, and how to use it correctly.
As a .Net developer, I have naturally gravitated toward Asp.Net for building web applications. However, the past few years I have eschewed web forms for the modern ajax style of development, especially the SPA. One reason I do still create .aspx pages is to build reports with tools like Telerik reporting or Microsoft .rdlc. I couldn’t find a good way to make reports without a server-side technology and The Google lead me down many sub-optimal paths. Finally, I have figured it out, and it was easy. I am embarrassed to announce that I didn’t know this before, but maybe some of you are as dumb as I am and this blog post could help.
Download Sample Visual Studio Solution
You have a web site or other http services that are secured via the ASP.Net Membership Provider and you want to access some of these resources from code – such as a class library or desktop application. Users of the web site obviously will be sent to a login page that takes their username and password and then authenticates the user. But how do you authenticate against the same Membership Provider when you are not using a web browser, and therfore cannot interact with a login page? Continue reading