30 March 2010

How to add a forms authentication cookie to the request

A common problem is how to add an forms authentication cookie to the request.
The solution is to add the forms authentication cookie when performing a HttpWebRequest.

Uri uri = new Uri("http://services.mysite.com/document/documentservice.svc");
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);       
HttpCookie cookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
Cookie authenticationCookie = new Cookie(FormsAuthentication.FormsCookieName, cookie.Value, cookie.Path, HttpContext.Current.Request.Url.Authority);
webRequest.CookieContainer = new CookieContainer();
WebResponse myResponse = webRequest.GetResponse();
Stream stream = myResponse.GetResponseStream();

04 March 2010

Patterns Parallel Programming

In the .NET Framework 4.0 there is a Parallel Programming model that is worth understanding.
I recommend the reading of
Patterns for Parallel Programming: Understanding and Applying Parallel Patterns with the .NET Framework 4

Good reading.