<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Emad Alashi&#039;s Blog &#187; ISession NHibernate EndRequest HttpApplication</title>
	<atom:link href="http://www.emadashi.com/index.php/tag/isession-nhibernate-endrequest-httpapplication/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.emadashi.com</link>
	<description></description>
	<lastBuildDate>Sun, 15 Jan 2012 10:05:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>HttpApplication EndRequest Event Invoked Many Times In Single Request?</title>
		<link>http://www.emadashi.com/index.php/2008/12/httpapplication-endrequest-event-invoked-many-times-in-single-request/</link>
		<comments>http://www.emadashi.com/index.php/2008/12/httpapplication-endrequest-event-invoked-many-times-in-single-request/#comments</comments>
		<pubDate>Sun, 14 Dec 2008 20:44:37 +0000</pubDate>
		<dc:creator>Emad Alashi</dc:creator>
				<category><![CDATA[Bunian]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[ISession NHibernate EndRequest HttpApplication]]></category>

		<guid isPermaLink="false">http://eashi.wordpress.com/2008/12/14/httpapplication-endrequest-event-invoked-many-times-in-single-request/</guid>
		<description><![CDATA[The other day I was putting the last touch of a temporary way to manage the NHibernate session (ISession) in Bunian. So part of the task was to bind a method to the HttpApplication EndRequest event (in the Global.asax.cs file) like the following:

public override void Init()
{
       this.EndRequest += WorkContext.NHibernateSessionManager.Instance.HttpRequestEnded;
}

By doing this, at the end of [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I was putting the last touch of a temporary way to manage the NHibernate session (ISession) in <a href="http://www.codeplex.com/bunian">Bunian</a>. So part of the task was to bind a method to the HttpApplication EndRequest event (in the Global.asax.cs file) like the following:</p>
<div style="font-size:12pt;background:#f2ebe3;color:black;font-family:courier new;">
<p style="margin:0;"><span style="color:blue;">public</span> <span style="color:blue;">override</span> <span style="color:blue;">void</span> Init()</p>
<p style="margin:0;">{</p>
<p style="margin:0;">       <span style="color:blue;">this</span>.EndRequest += WorkContext.<span style="color:#2b91af;">NHibernateSessionManager</span>.Instance.HttpRequestEnded;</p>
<p style="margin:0;">}</p>
</div>
<p>By doing this, at the end of each page request the <strong>NHibernateSessionManager.Instance.HttpRequestEnded()</strong> will be called and I can clean the session then. But to my surprise this method was called at least 10 times!! So I thought maybe the <strong>Global.Init() </strong>method is called many times for some reason and I ended up binding the same method to the EndRequest event many times, so I set a breakpoint at the Global.Init() method and&#8230;it&#8217;s called one time only.</p>
<p>That was strange, ok so it&#8217;s only the HttpRequestEnded() mehtod that is called many times, but I am requesting only one page!! how come there are 10 requests!</p>
<p>So I opened Firefox which is already &#8220;armed&#8221; with the magnificent add-on <a href="http://getfirebug.com/">Firebug</a>, and I requested the page again, Firebug showed the following:</p>
<p><a href="http://eashi.files.wordpress.com/2008/12/croppercapture1.jpg"><img style="border-width:0;" src="http://eashi.files.wordpress.com/2008/12/croppercapture1-thumb.jpg" border="0" alt="CropperCapture[1]" width="664" height="272" /></a></p>
<p>And that was it!! the page contained 10 resources (1 CSS file and 9 images), OH! so <em>it is </em>one page, but for each resource referenced on the page you get a request, hence a raise of the EndRequest event.</p>
<p>I couldn&#8217;t love Firebug more; I am not only happy that I wasn&#8217;t doing something wrong, but yet I learned something new about the ASP.NET internals. awesome.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emadashi.com/index.php/2008/12/httpapplication-endrequest-event-invoked-many-times-in-single-request/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

