Cookie header appears twice when added in BeginRequest

Sinilioptilky

New Member
When the following IHttpModule is registered I get duplicate cookie headers for cookie_BeginRequest.\[code\]public class MyModule : IHttpModule{ public void Init(HttpApplication context) { context.BeginRequest+=(sender, e) => { SetValues("BeginRequest"); }; context.PreSendRequestContent+=(sender, e) => { SetValues("PreSendRequestContent"); }; } static void SetValues(string name) { var httpContext = HttpContext.Current; var httpCookie = new HttpCookie("cookie_" + name, "cookie_value"); httpContext.Response.Cookies.Add(httpCookie); httpContext.Response.Headers.Add("header_" + name, "header_value"); } public void Dispose() { }}\[/code\]I would expect to see the following headers:\[quote\] header_BeginRequest: header_value Set-Cookie: cookie_BeginRequest=cookie_value; path=/ header_PreSendRequestContent: header_value Set-Cookie: cookie_PreSendRequestContent=cookie_value; path=/\[/quote\]Instead I see (note the duplicate Set-Cookie cookie_BeginRequest):\[quote\] header_BeginRequest: header_value Set-Cookie: cookie_BeginRequest=cookie_value; path=/ Set-Cookie: cookie_BeginRequest=cookie_value; path=/ header_PreSendRequestContent: header_value Set-Cookie: cookie_PreSendRequestContent=cookie_value; path=/\[/quote\]The headers above were extracted from Fiddler to exclude the browser being the source of the problem.I have stepped through the code and it appears that the BeginRequest event is only firing once per request. This is backed up by the fact that the header_BeginRequest header only appears once. I have also checked that the module is only registered once. The tests were all run under IIS Express and .Net 4.5.Is this expected behavior?
 
Back
Top