I am currently building a reverse proxy by using HttpHandler, more or less I followed the example at http://www.codeproject.com/Articles/31329/Simple-Reverse-Proxy-in-C-2-0-description-and-depl and I created my own project andswitched to .net 4.0.
In one of the feature I tested to use cookie, I noticed IIS Express is not able to store cookie back to browser from HttpHandler.
I have created a web page/site (to be proxied) and added a cookie in one of the ASPX page. In HttpHandler after getting the response from remote server (which set the cookie), there is a piece of code
context.Response.Cookies.Clear(); foreach (Cookie receivedCookie in response.Cookies) { HttpCookie c = new HttpCookie(receivedCookie.Name, receivedCookie.Value); c.Domain = context.Request.Url.Host; c.Expires = receivedCookie.Expires; c.HttpOnly = receivedCookie.HttpOnly; c.Path = receivedCookie.Path; c.Secure = receivedCookie.Secure; context.Response.Cookies.Add(c); }
to read the cookie from proxied server and add to current http context. I set the break point and I can see the cookie has been returned and the loop has been executed. But HttpContext fails to write the cookie to browser.
I deploiyed the code as is to a Windows 2003 IIS6 server, and I can get the cookie value without problem. I will do further testing on a Windows 2008 IIS7 server later. So the code itself is correct, but IIS Express 8 could not handle cookie correctly.