<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Eran Nachum's Blog</title>
    <link>http://www.eranachum.com/</link>
    <description>www.eranachum.com - Implementing &amp; executing my thoughts...</description>
    <language>en-us</language>
    <copyright>Eran Nachum</copyright>
    <lastBuildDate>Mon, 28 Jun 2010 14:34:00 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 1.8.5223.2</generator>
    <managingEditor>eranachum@hotmail.com</managingEditor>
    <webMaster>eranachum@hotmail.com</webMaster>
    <item>
      <trackback:ping>http://www.eranachum.com/Trackback.aspx?guid=7f7734e4-20df-4054-995d-e321ad923f61</trackback:ping>
      <pingback:server>http://www.eranachum.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.eranachum.com/PermaLink,guid,7f7734e4-20df-4054-995d-e321ad923f61.aspx</pingback:target>
      <dc:creator>eranachum@hotmail.com (Eran Nachum)</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
      Great post in regards asp.net &amp; Json.
   </p>
        <p>
      I wasn’t familiar with <a title="System.Web.Script.Serialization.JavaScriptSerializer" href="http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx" target="_blank">System.Web.Script.Serialization.JavaScriptSerializer</a> which
      provides serialization and deserialization functionality for AJAX-enabled applications.
   </p>
        <p>
      While searching the web in regards this issue, I bumped into a great post that outlines
      the usage of this namespace.
   </p>
        <p>
      You can check it out <a href="http://blogs.msdn.com/b/rakkimk/archive/2009/01/30/asp-net-json-serialization-and-deserialization.aspx" target="_blank">here</a>.
   </p>
        <p>
      Good Luck.
   </p>
        <img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=7f7734e4-20df-4054-995d-e321ad923f61" />
      </body>
      <title>ASP.NET &amp;ndash; JSON &amp;ndash; Serialization and Deserialization</title>
      <guid>http://www.eranachum.com/PermaLink,guid,7f7734e4-20df-4054-995d-e321ad923f61.aspx</guid>
      <link>http://www.eranachum.com/PermaLink,guid,7f7734e4-20df-4054-995d-e321ad923f61.aspx</link>
      <pubDate>Mon, 28 Jun 2010 14:34:00 GMT</pubDate>
      <description>&lt;p&gt;
   Great post in regards asp.net &amp;amp; Json.
&lt;/p&gt;
&lt;p&gt;
   I wasn’t familiar with &lt;a title="System.Web.Script.Serialization.JavaScriptSerializer" href="http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx" target="_blank"&gt;System.Web.Script.Serialization.JavaScriptSerializer&lt;/a&gt; which
   provides serialization and deserialization functionality for AJAX-enabled applications.
&lt;/p&gt;
&lt;p&gt;
   While searching the web in regards this issue, I bumped into a great post that outlines
   the usage of this namespace.
&lt;/p&gt;
&lt;p&gt;
   You can check it out &lt;a href="http://blogs.msdn.com/b/rakkimk/archive/2009/01/30/asp-net-json-serialization-and-deserialization.aspx" target="_blank"&gt;here&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
   Good Luck.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=7f7734e4-20df-4054-995d-e321ad923f61" /&gt;</description>
      <category>ASP.NET;C#;JSON</category>
    </item>
    <item>
      <trackback:ping>http://www.eranachum.com/Trackback.aspx?guid=62a8a5f9-888a-41ed-9cfe-16d7fe062fa5</trackback:ping>
      <pingback:server>http://www.eranachum.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.eranachum.com/PermaLink,guid,62a8a5f9-888a-41ed-9cfe-16d7fe062fa5.aspx</pingback:target>
      <dc:creator>eranachum@hotmail.com (Eran Nachum)</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
      Great post by Omar Al Zabir on regards best practices for creating websites in IIS
      6.
   </p>
        <p>
      This post will demonstrate you step by step how to make your website more scalability
      and cachable.
   </p>
        <p>
          <a href="http://msmvps.com/blogs/omar/archive/2008/10/04/best-practices-for-creating-websites-in-iis-6-0.aspx">http://msmvps.com/blogs/omar/archive/2008/10/04/best-practices-for-creating-websites-in-iis-6-0.aspx</a>
        </p>
        <img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=62a8a5f9-888a-41ed-9cfe-16d7fe062fa5" />
      </body>
      <title>Best practices for creating websites in IIS 6.0</title>
      <guid>http://www.eranachum.com/PermaLink,guid,62a8a5f9-888a-41ed-9cfe-16d7fe062fa5.aspx</guid>
      <link>http://www.eranachum.com/PermaLink,guid,62a8a5f9-888a-41ed-9cfe-16d7fe062fa5.aspx</link>
      <pubDate>Thu, 16 Oct 2008 08:41:05 GMT</pubDate>
      <description>&lt;p&gt;
   Great post by Omar Al Zabir on regards best practices for creating websites in IIS
   6.
&lt;/p&gt;
&lt;p&gt;
   This post will demonstrate you step by step how to make your website more scalability
   and cachable.
&lt;/p&gt;
&lt;p&gt;
   &lt;a href="http://msmvps.com/blogs/omar/archive/2008/10/04/best-practices-for-creating-websites-in-iis-6-0.aspx"&gt;http://msmvps.com/blogs/omar/archive/2008/10/04/best-practices-for-creating-websites-in-iis-6-0.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=62a8a5f9-888a-41ed-9cfe-16d7fe062fa5" /&gt;</description>
      <category>ASP.NET;System</category>
    </item>
    <item>
      <trackback:ping>http://www.eranachum.com/Trackback.aspx?guid=87af9208-ddc2-486f-854d-1246baeb26f6</trackback:ping>
      <pingback:server>http://www.eranachum.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.eranachum.com/PermaLink,guid,87af9208-ddc2-486f-854d-1246baeb26f6.aspx</pingback:target>
      <dc:creator>eranachum@hotmail.com (Eran Nachum)</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
      I faced a 'problem' while needed to add a postback event to the server while generating
      client code from the server on runtime. 
   </p>
        <p>
      You could think about a way of creating server control in the code behind and attaching
      it an event to its OnClick (or other event), but this one is good enough only to server
      controls that knows to do postback.
   </p>
        <p>
      What will you do if you'll want to add postback event to a generic client control
      such as html-table-cell of other client controls that doesn't need to contact the
      server beside the postback event?
   </p>
        <p>
      The <strong>GetPostBackEventReference</strong> method of the Page object's ClientScript
      property supports this action and let you perform this action. By MSDN property summary,
      this one <em>"Returns a string that can be used in a client event to cause postback
      to the server. The reference string is defined by the specified control that handles
      the postback and a string argument of additional event information".</em></p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
      ...<br /><br /></span>
          </span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">TableCell
      tc <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> TableCell();<br /><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
      Add some attributes or styling...</span><br />
      tc.Attributes.Add(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"onclick"</span>,
      Page.ClientScript.GetPostBackEventReference(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">this</span>,
      &lt;argument&gt;));<br /><br /><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
      Do you stuff (add the cell to the table) etc.</span></span>
        </p>
        <img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=87af9208-ddc2-486f-854d-1246baeb26f6" />
      </body>
      <title>Setting Client Event to cause a Server Postback - The Right Approach</title>
      <guid>http://www.eranachum.com/PermaLink,guid,87af9208-ddc2-486f-854d-1246baeb26f6.aspx</guid>
      <link>http://www.eranachum.com/PermaLink,guid,87af9208-ddc2-486f-854d-1246baeb26f6.aspx</link>
      <pubDate>Wed, 07 May 2008 13:40:56 GMT</pubDate>
      <description>&lt;p&gt;
   I faced a 'problem' while needed to add a postback event to the server while generating
   client code from the server on runtime. 
&lt;/p&gt;
&lt;p&gt;
   You could think about a way of creating server control in the code behind and attaching
   it an event to its OnClick (or other event), but this one is good enough only to server
   controls that knows to do postback.
&lt;/p&gt;
&lt;p&gt;
   What will you do if you'll want to add postback event to a generic client control
   such as html-table-cell of other client controls that doesn't need to contact the
   server beside the postback event?
&lt;/p&gt;
&lt;p&gt;
   The &lt;strong&gt;GetPostBackEventReference&lt;/strong&gt; method of the Page object's ClientScript
   property supports this action and let you perform this action. By MSDN property summary,
   this one &lt;em&gt;"Returns a string that can be used in a client event to cause postback
   to the server. The reference string is defined by the specified control that handles
   the postback and a string argument of additional event information".&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
   ...&lt;br&gt;
   &lt;br&gt;
   &lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;TableCell
   tc &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; TableCell();&lt;br&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
   Add some attributes or styling...&lt;/span&gt;
   &lt;br&gt;
   tc.Attributes.Add(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"onclick"&lt;/span&gt;,
   Page.ClientScript.GetPostBackEventReference(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;this&lt;/span&gt;,
   &amp;lt;argument&amp;gt;));&lt;br&gt;
   &lt;br&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
   Do you stuff (add the cell to the table) etc.&lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=87af9208-ddc2-486f-854d-1246baeb26f6" /&gt;</description>
      <category>ASP.NET</category>
    </item>
    <item>
      <trackback:ping>http://www.eranachum.com/Trackback.aspx?guid=9fafbb58-dd14-4ab4-beb8-e29999caba1d</trackback:ping>
      <pingback:server>http://www.eranachum.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.eranachum.com/PermaLink,guid,9fafbb58-dd14-4ab4-beb8-e29999caba1d.aspx</pingback:target>
      <dc:creator>eranachum@hotmail.com (Eran Nachum)</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
      I read a great article about performance and scalability. Some of the issues there
      were helped me a lot and the rest were sharpen my knowledge.
   </p>
        <p>
      So, if you are an ASP.NET developer (beginner or senior), It is recommended for you
      to read that one by <strong>Omar Al Zabir</strong> at the codeproject site <a href="http://www.codeproject.com/KB/aspnet/10ASPNetPerformance.aspx" target="_blank">here</a>. 
   </p>
        <p>
      Some if the things that he talks about are: ASP.NET pipeline optimization, Things
      you must do for ASP.NET before going live, Caching AJAX calls on browse and more...
   </p>
        <p>
      Worth a reading...
   </p>
        <img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=9fafbb58-dd14-4ab4-beb8-e29999caba1d" />
      </body>
      <title>Great Article about ASP.NET Performance and Scalability</title>
      <guid>http://www.eranachum.com/PermaLink,guid,9fafbb58-dd14-4ab4-beb8-e29999caba1d.aspx</guid>
      <link>http://www.eranachum.com/PermaLink,guid,9fafbb58-dd14-4ab4-beb8-e29999caba1d.aspx</link>
      <pubDate>Wed, 06 Feb 2008 15:08:10 GMT</pubDate>
      <description>&lt;p&gt;
   I read a great article about performance and scalability. Some of the issues there
   were helped me a lot and the rest were sharpen my knowledge.
&lt;/p&gt;
&lt;p&gt;
   So, if you are an ASP.NET developer (beginner or senior), It is recommended for you
   to read that one by &lt;strong&gt;Omar Al Zabir&lt;/strong&gt; at the codeproject site &lt;a href="http://www.codeproject.com/KB/aspnet/10ASPNetPerformance.aspx" target="_blank"&gt;here&lt;/a&gt;. 
&lt;/p&gt;
&lt;p&gt;
   Some if the things that he talks about are: ASP.NET pipeline optimization, Things
   you must do for ASP.NET before going live, Caching AJAX calls on browse and more...
&lt;/p&gt;
&lt;p&gt;
   Worth a reading...
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=9fafbb58-dd14-4ab4-beb8-e29999caba1d" /&gt;</description>
      <category>ASP.NET;Code;Patterns;Web scalability</category>
    </item>
    <item>
      <trackback:ping>http://www.eranachum.com/Trackback.aspx?guid=089badbf-c01c-4363-a236-617ccf85ce3b</trackback:ping>
      <pingback:server>http://www.eranachum.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.eranachum.com/PermaLink,guid,089badbf-c01c-4363-a236-617ccf85ce3b.aspx</pingback:target>
      <dc:creator>eranachum@hotmail.com (Eran Nachum)</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
      The reason I published this post is because I didn't find any result when googling
      the error description and solved it myself at last.
   </p>
        <p>
      If you're asp.net developers you probably know the <a href="http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.objectdatasource.aspx" target="_blank">ObjectDataSource</a> object,
      which represents a business object that provides data to data-bound controls in multi-tier
      Web application architectures.
   </p>
        <p>
      I like this object, most of the time this object can solve you all the annoying steps
      logic of calling the BL/DAL object in order to retrieve the data and populate the
      wanted presentation control.
   </p>
        <p>
      On one of my working on website's pages (which is quite complex one that knows to
      list data from several sources and procedures), I am using such of object as a data
      source in the main GridView that renders a list of records. In order to interact with
      each different select method I had to set every time the SelectMethod property and
      it's specific parameters in the code-behind. Until now everything is just fine...
   </p>
        <p>
      It seems that working this way affects the other postback events on the page, (because
      after event postback, the OnInit and OnLoad events are being called first and just
      after it the event handler itself is being called), here my page was crashed and gave
      this error message: "<i>The Select operation is not supported by ObjectDataSource
      '&lt;objectdatasource_id&gt;' unless the SelectMethod is specified.</i>"
   </p>
        <p>
      This error caused because the page expected the SelectMethod property to be initialized
      between the OnInit and OnLoad methods and just after it the rest of the events.
   </p>
        <p>
      The resolution is quite easy in this case; 
   </p>
        <p>
      First, you need to remove the ObjectDataSourceID property definition from the control
      properties' definitions layout in the control source and set the DataSource for the
      control to the desired one in the OnInit method. After it, in the OnPreRender method
      call the control's DataBind method in order to bind the data source. This last action
      will allow to any event to happen and just after it to set up the Control (the GridView
      in my case) with data.
   </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">protected</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">override</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> OnInit(EventArgs
      e)<br />
      {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   base</span>.OnInit(e);<br />
         MyGridView.DataSource <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> MyObjectDataSource;<br />
      }<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">protected</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">override</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> OnPreRender(EventArgs
      e)<br />
      {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   base</span>.OnPreRender(e);<br />
         MyGridView.DataBind();<br />
      }</span>
        </p>
        <p>
      I hope it'll help anyone...
   </p>
        <img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=089badbf-c01c-4363-a236-617ccf85ce3b" />
      </body>
      <title>Manually Set ObjectDataSource.SelectMethod Property BUG</title>
      <guid>http://www.eranachum.com/PermaLink,guid,089badbf-c01c-4363-a236-617ccf85ce3b.aspx</guid>
      <link>http://www.eranachum.com/PermaLink,guid,089badbf-c01c-4363-a236-617ccf85ce3b.aspx</link>
      <pubDate>Wed, 12 Dec 2007 23:02:19 GMT</pubDate>
      <description>&lt;p&gt;
   The reason I published this post is because I didn't find any result when googling
   the error description and solved it myself at last.
&lt;/p&gt;
&lt;p&gt;
   If you're asp.net developers you probably know the &lt;a href="http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.objectdatasource.aspx" target=_blank&gt;ObjectDataSource&lt;/a&gt; object,
   which represents a business object that provides data to data-bound controls in multi-tier
   Web application architectures.
&lt;/p&gt;
&lt;p&gt;
   I like this object, most of the time this object can solve you all the annoying steps
   logic of calling the BL/DAL object in order to retrieve the data and populate the
   wanted presentation control.
&lt;/p&gt;
&lt;p&gt;
   On one of my working on website's pages (which is quite complex one that knows to
   list data from several sources and procedures), I am using such of object as a data
   source in the main GridView that renders a list of records. In order to interact with
   each different select method I had to set every time the SelectMethod property and
   it's specific parameters in the code-behind. Until now everything is just fine...
&lt;/p&gt;
&lt;p&gt;
   It seems that working this way affects the other postback events on the page, (because
   after event postback, the OnInit and OnLoad events are being called first and just
   after it the event handler itself is being called), here my page was crashed and gave
   this error message: "&lt;i&gt;The Select operation is not supported by ObjectDataSource
   '&amp;lt;objectdatasource_id&amp;gt;' unless the SelectMethod is specified.&lt;/i&gt;"
&lt;/p&gt;
&lt;p&gt;
   This error caused because the page expected the SelectMethod property to be initialized
   between the OnInit and OnLoad methods and just after it the rest of the events.
&lt;/p&gt;
&lt;p&gt;
   The resolution is quite easy in this case; 
&lt;/p&gt;
&lt;p&gt;
   First, you need to remove the ObjectDataSourceID property definition from the control
   properties' definitions layout in the control source and set the DataSource for the
   control to the desired one in the OnInit method. After it, in the OnPreRender method
   call the control's DataBind method in order to bind the data source. This last action
   will allow to any event to happen and just after it to set up the Control (the GridView
   in my case) with data.
&lt;/p&gt;
&lt;p&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;protected&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;override&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; OnInit(EventArgs
   e)&lt;br&gt;
   {&lt;br&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;base&lt;/span&gt;.OnInit(e);&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;MyGridView.DataSource &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; MyObjectDataSource;&lt;br&gt;
   }&lt;br&gt;
   &lt;br&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;protected&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;override&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; OnPreRender(EventArgs
   e)&lt;br&gt;
   {&lt;br&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;base&lt;/span&gt;.OnPreRender(e);&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;MyGridView.DataBind();&lt;br&gt;
   }&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
   I hope it'll help anyone...
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=089badbf-c01c-4363-a236-617ccf85ce3b" /&gt;</description>
      <category>.NET 2005;ASP.NET;Bugs;C#</category>
    </item>
    <item>
      <trackback:ping>http://www.eranachum.com/Trackback.aspx?guid=e14f3ec2-bf1e-4a9c-8cf2-cf8852066bb5</trackback:ping>
      <pingback:server>http://www.eranachum.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.eranachum.com/PermaLink,guid,e14f3ec2-bf1e-4a9c-8cf2-cf8852066bb5.aspx</pingback:target>
      <dc:creator>eranachum@hotmail.com (Eran Nachum)</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
      This post comes as a continues to the previous <a href="http://www.eranachum.com/PermaLink,guid,7e3769f9-bf81-4b9f-9131-eddfac599ed4.aspx">one</a>.
      I thought about some insights regarding this issue and in the bottom line, there are
      some significant disadvantages that I could think about:
   </p>
        <ol>
          <li>
         Get from the starter point that web application is stateless, this is the most important
         disadvantage - you cannot rely on that admit it or not.</li>
          <li>
         What about performance - like the former post, this kind of alive (web) service will
         grab a thread permanently from the application pool and we'll use it - this thing
         damage in a matter of time the performance.</li>
          <li>
         What about IIS reset action. If being done, the process will be 'dead' and this thing
         is worth to nothing because we can't rely on anyone to check if it alive.</li>
        </ol>
        <p>
          <strong>The main conclusion:</strong>
        </p>
        <p>
      Don't count on web application in order to run scheduled tasks - you can't rely on
      it in 100% (however you have tools that meant to monitor it).
   </p>
        <p>
      I takes <a href="http://www.kenegozi.com/blog/" target="_blank">Ken Egozi</a>'s comment
      of creating a scheduled task (instead of windows service) that will do the scheduled
      job (I going to keep my local machine alive forever I think ;))
   </p>
        <img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=e14f3ec2-bf1e-4a9c-8cf2-cf8852066bb5" />
      </body>
      <title>Scheduled Task in Web Application - Insights</title>
      <guid>http://www.eranachum.com/PermaLink,guid,e14f3ec2-bf1e-4a9c-8cf2-cf8852066bb5.aspx</guid>
      <link>http://www.eranachum.com/PermaLink,guid,e14f3ec2-bf1e-4a9c-8cf2-cf8852066bb5.aspx</link>
      <pubDate>Tue, 04 Dec 2007 17:00:48 GMT</pubDate>
      <description>&lt;p&gt;
   This post comes as a continues to the previous &lt;a href="http://www.eranachum.com/PermaLink,guid,7e3769f9-bf81-4b9f-9131-eddfac599ed4.aspx"&gt;one&lt;/a&gt;.
   I thought about some insights regarding this issue and in the bottom line, there are
   some significant disadvantages that I could think about:
&lt;/p&gt;
&lt;ol&gt;
   &lt;li&gt;
      Get from the starter point that web application is stateless, this is the most important
      disadvantage - you cannot rely on that admit it or not.&lt;/li&gt;
   &lt;li&gt;
      What about performance - like the former post, this kind of alive (web) service will
      grab a thread permanently from the application pool and we'll use it - this thing
      damage in a matter of time the performance.&lt;/li&gt;
   &lt;li&gt;
      What about IIS reset action. If being done, the process will be 'dead' and this thing
      is worth to nothing because we can't rely on anyone to check if it alive.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
   &lt;strong&gt;The main conclusion:&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
   Don't count on web application in order to run scheduled tasks - you can't rely on
   it in 100% (however you have tools that meant to monitor it).
&lt;/p&gt;
&lt;p&gt;
   I takes &lt;a href="http://www.kenegozi.com/blog/" target="_blank"&gt;Ken Egozi&lt;/a&gt;'s comment
   of creating a scheduled task (instead of windows service) that will do the scheduled
   job (I going to keep my local machine alive forever I think ;))
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=e14f3ec2-bf1e-4a9c-8cf2-cf8852066bb5" /&gt;</description>
      <category>ASP.NET;System</category>
    </item>
    <item>
      <trackback:ping>http://www.eranachum.com/Trackback.aspx?guid=7e3769f9-bf81-4b9f-9131-eddfac599ed4</trackback:ping>
      <pingback:server>http://www.eranachum.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.eranachum.com/PermaLink,guid,7e3769f9-bf81-4b9f-9131-eddfac599ed4.aspx</pingback:target>
      <dc:creator>eranachum@hotmail.com (Eran Nachum)</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
      I have a problem (or used to have a problem...). In my working on web 2.0 startup,
      I bumped in a problem which in first thought looked to me as a simple one but after
      something like 5 seconds I figured out that it's actually a problem (or something
      to think about - I like this phrase much better ;)).
   </p>
        <p>
      So after this introduction, lets introduce the 'something to think about' issue: I
      had to run each period of time a set of tasks in order to update some database statuses.
      If my web application was hosted on a dedicated server, this one had be solved very
      quickly; windows service - I guess you thought about it yourselves...
   </p>
        <p>
      BUT, we are not going to host this web 2.0 application in a dedicated server (at least
      not now) and the scheduled task became a task itself, because (if you are web developers
      you'd better know) application is lives as long as there is at least one client that
      consumes it. When the last consumer is going home, also the application in going home
      to relax... 
   </p>
        <p>
          <strong>Now to the main question: how can we keep it alive?</strong>
        </p>
        <p>
      After doing some thinking between me and myself, gathering up some good resolutions
      and not I thought about good one; in your web application create a web service that
      most of its job is to expose a <em>KeepAlive</em> web method that will return a dummy
      value and will keep the web application alive all the time and also will perform the
      tasks that you to establish for permanent period of time.
   </p>
        <p>
      In your local PC, create a small desktop application in order to handle the tasks.
      This application will be a windows service that will run automatically under your
      machine every X interval and will ping the web service in order to keep the web application
      alive. 
   </p>
        <p>
      Note: the web service itself will know to execute the specific task itself every predefined
      period of time.
   </p>
        <p>
          <em>What about performance?</em> This solution could affect your web application performance
      (I think that you know the reason why), in this case you can create another wen
      application that will be placed in the same server and all its job is to be kept alive
      and perform your tasks.
   </p>
        <p>
      Any addition will be appreciated... I am going to write this web service now...
   </p>
        <img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=7e3769f9-bf81-4b9f-9131-eddfac599ed4" />
      </body>
      <title>Scheduled Task in Web Application - Is it can be done?</title>
      <guid>http://www.eranachum.com/PermaLink,guid,7e3769f9-bf81-4b9f-9131-eddfac599ed4.aspx</guid>
      <link>http://www.eranachum.com/PermaLink,guid,7e3769f9-bf81-4b9f-9131-eddfac599ed4.aspx</link>
      <pubDate>Mon, 03 Dec 2007 16:01:39 GMT</pubDate>
      <description>&lt;p&gt;
   I have a problem (or used to have a problem...). In my working on web 2.0 startup,
   I bumped in a problem which in first thought looked to me as a simple one but after
   something like 5 seconds I figured out that it's actually a problem (or something
   to think about - I like this phrase much better ;)).
&lt;/p&gt;
&lt;p&gt;
   So after this introduction, lets introduce the 'something to think about' issue: I
   had to run each period of time a set of tasks in order to update some database statuses.
   If my web application was hosted on a dedicated server, this one had be solved very
   quickly; windows service - I guess you thought about it yourselves...
&lt;/p&gt;
&lt;p&gt;
   BUT, we are not going to host this web 2.0 application in a dedicated server (at least
   not now) and the scheduled task became a task itself, because (if you are web developers
   you'd better know) application is lives as long as there is at least one client that
   consumes it. When the last consumer is going home, also the application in going home
   to relax... 
&lt;/p&gt;
&lt;p&gt;
   &lt;strong&gt;Now to the main question: how can we keep it alive?&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
   After doing some thinking between me and myself, gathering up some good resolutions
   and not I thought about good one; in your web application create a web service that
   most of its job is to expose a &lt;em&gt;KeepAlive&lt;/em&gt; web method that will return a dummy
   value and will keep the web application alive all the time and also will perform the
   tasks that you to establish for permanent period of time.
&lt;/p&gt;
&lt;p&gt;
   In your local PC, create a small desktop application in order to handle the tasks.
   This application will be a windows service that will run automatically under your
   machine every X interval and will ping the web service in order to keep the web application
   alive. 
&lt;/p&gt;
&lt;p&gt;
   Note: the web service itself will know to execute the specific task itself every predefined
   period of time.
&lt;/p&gt;
&lt;p&gt;
   &lt;em&gt;What about performance?&lt;/em&gt; This solution could affect your web application performance
   (I think that you know&amp;nbsp;the reason why), in this case you can create another wen
   application that will be placed in the same server and all its job is to be kept alive
   and perform your tasks.
&lt;/p&gt;
&lt;p&gt;
   Any addition will be appreciated... I am going to write this web service now...
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=7e3769f9-bf81-4b9f-9131-eddfac599ed4" /&gt;</description>
      <category>ASP.NET;Patterns;Web Services</category>
    </item>
    <item>
      <trackback:ping>http://www.eranachum.com/Trackback.aspx?guid=b962b643-ec30-48ad-83d0-a154a922e83f</trackback:ping>
      <pingback:server>http://www.eranachum.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.eranachum.com/PermaLink,guid,b962b643-ec30-48ad-83d0-a154a922e83f.aspx</pingback:target>
      <dc:creator>eranachum@hotmail.com (Eran Nachum)</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
      Have you also had some mysterious AJAX error/bugs/strange behavior? If does, this
      following link maybe will be helpfull for you... Dave Ward speards 2 common mistakes
      about it <a href="http://encosia.com/2007/10/24/are-you-making-these-3-common-aspnet-ajax-mistakes/" target="_blank">here</a>. 
   </p>
        <p>
      BTW, Found it through <a href="http://weblogs.asp.net/scottgu/" target="_blank">ScottGu's
      blog</a>.
   </p>
        <p>
      Enjoy
   </p>
        <img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=b962b643-ec30-48ad-83d0-a154a922e83f" />
      </body>
      <title>Are you making these 3 common ASP.NET AJAX Mistakes?</title>
      <guid>http://www.eranachum.com/PermaLink,guid,b962b643-ec30-48ad-83d0-a154a922e83f.aspx</guid>
      <link>http://www.eranachum.com/PermaLink,guid,b962b643-ec30-48ad-83d0-a154a922e83f.aspx</link>
      <pubDate>Mon, 29 Oct 2007 09:11:22 GMT</pubDate>
      <description>&lt;p&gt;
   Have you also had some mysterious AJAX error/bugs/strange behavior? If does, this
   following link maybe will be helpfull for you... Dave Ward speards 2 common mistakes
   about it&amp;nbsp;&lt;a href="http://encosia.com/2007/10/24/are-you-making-these-3-common-aspnet-ajax-mistakes/" target=_blank&gt;here&lt;/a&gt;. 
&lt;/p&gt;
&lt;p&gt;
   BTW, Found it through &lt;a href="http://weblogs.asp.net/scottgu/" target=_blank&gt;ScottGu's
   blog&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
   Enjoy
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=b962b643-ec30-48ad-83d0-a154a922e83f" /&gt;</description>
      <category>AJAX;ASP.NET</category>
    </item>
    <item>
      <trackback:ping>http://www.eranachum.com/Trackback.aspx?guid=ea5366a9-58bf-420a-abe4-395e9b9c72b5</trackback:ping>
      <pingback:server>http://www.eranachum.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.eranachum.com/PermaLink,guid,ea5366a9-58bf-420a-abe4-395e9b9c72b5.aspx</pingback:target>
      <dc:creator>eranachum@hotmail.com (Eran Nachum)</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
      I had a little debate (friendly one of course) with one of my work colleagues, caller
      Lior Alon about the usage and the necesasry of this technique. At the start of our
      conversation we disagreed on several things like: "It must stay for the good work
      flow", "This is by Microsoft design - do not touch" and more and more... 
      <br />
      But at least we agredd that in some cases this ViewState is unnecessary and it has
      some disadvengtages that come over the adventages in some cases.
   </p>
        <p>
      From the initial point of view, I would change the ViewState behavior. By defaut
      the ViewState of each ASP.NET web page is always on, so when you develop a new page
      you need to consider that the ViewState is on - so expect to amount of encrypted lltterals
      on the top of your page (according  the web server controls that you rendered
      on your page). 
   </p>
        <p>
      This issue has some disadvanteges as I said earlier:
   </p>
        <ol>
          <li>
         Big size of data that comes from the sevrer to the client (response time concerns). 
      </li>
          <li>
         SEO (Search Engines Optimization) - Most of the seerch engines doesn't indexes the
         whole page (and I think non of then but I am not sure of it). The exsitance of the
         ViewState in the top of the prevent these search engines from index the relevant data
         from the specific page and here the ViewState takes its place. Here comes the question
         why the ViewState must be on the top of the page instread of its bottom? 
      </li>
          <li>
         By default the ViewState in on; In some cases, static pages contains web server controls
         that doesn't need to be updated from the server by the user demand. In this case each
         control has its own ViewState and it being populated to the bunch of the ViewState's
         encrypted data. (In that case you can develop this page using HTML controls that doesn't
         drag to the page 'added value'...</li>
        </ol>
        <p>
          <strong>So, to the conclution...</strong>
        </p>
        <p>
      ViewState is not bad thing, but like everything in life has some good and bad 'habbits'.
      After time of thinking, I think that the default behavoir of the ViewState should
      be off and the developer that creates her ASP.NET web page should be smart
      enough to use it wisely.
   </p>
        <p>
      What do you think?
   </p>
        <img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=ea5366a9-58bf-420a-abe4-395e9b9c72b5" />
      </body>
      <title>ASP.NET View State, is it realy necessary?</title>
      <guid>http://www.eranachum.com/PermaLink,guid,ea5366a9-58bf-420a-abe4-395e9b9c72b5.aspx</guid>
      <link>http://www.eranachum.com/PermaLink,guid,ea5366a9-58bf-420a-abe4-395e9b9c72b5.aspx</link>
      <pubDate>Thu, 25 Oct 2007 07:41:27 GMT</pubDate>
      <description>&lt;p&gt;
   I had a little debate (friendly one of course) with one of my work colleagues, caller
   Lior Alon about the usage and the necesasry of this technique. At the start of our
   conversation we disagreed on several things like: "It must stay for the good work
   flow", "This is by Microsoft design - do not touch" and more and more... 
   &lt;br&gt;
   But at least we agredd that in some cases this ViewState is unnecessary and it has
   some disadvengtages that come over the adventages in some cases.
&lt;/p&gt;
&lt;p&gt;
   From the initial point of view, I would change&amp;nbsp;the ViewState behavior. By defaut
   the ViewState of each ASP.NET web page is always on, so when you develop a new page
   you need to consider that the ViewState is on - so expect to amount of encrypted lltterals
   on the top of your page (according&amp;nbsp; the web server controls that you rendered
   on your page). 
&lt;/p&gt;
&lt;p&gt;
   This issue has some disadvanteges as I said earlier:
&lt;/p&gt;
&lt;ol&gt;
   &lt;li&gt;
      Big size of data that comes from the sevrer to the client (response time concerns). 
   &lt;li&gt;
      SEO (Search Engines Optimization) - Most of the seerch engines doesn't indexes the
      whole page (and I think non of then but I am not sure of it). The exsitance of the
      ViewState in the top of the prevent these search engines from index the relevant data
      from the specific page and here the ViewState takes its place. Here comes the question
      why the ViewState must be on the top of the page instread of its bottom? 
   &lt;li&gt;
      By default the ViewState in on; In some cases, static pages contains web server controls
      that doesn't need to be updated from the server by the user demand. In this case each
      control has its own ViewState and it being populated to the bunch of the ViewState's
      encrypted data. (In that case you can develop this page using HTML controls that doesn't
      drag to the page 'added value'...&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
   &lt;strong&gt;So, to the conclution...&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
   ViewState is not bad thing, but like everything in life has some good and bad 'habbits'.
   After time of thinking, I think that the default behavoir of the ViewState should
   be off and the developer that creates her ASP.NET web page&amp;nbsp;should&amp;nbsp;be smart
   enough to use it wisely.
&lt;/p&gt;
&lt;p&gt;
   What do you think?
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=ea5366a9-58bf-420a-abe4-395e9b9c72b5" /&gt;</description>
      <category>ASP.NET</category>
    </item>
    <item>
      <trackback:ping>http://www.eranachum.com/Trackback.aspx?guid=a23b7e24-df2c-4305-9bbd-b6a90fc6b4e0</trackback:ping>
      <pingback:server>http://www.eranachum.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.eranachum.com/PermaLink,guid,a23b7e24-df2c-4305-9bbd-b6a90fc6b4e0.aspx</pingback:target>
      <dc:creator>eranachum@hotmail.com (Eran Nachum)</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
      Lately I am focusing more and more on the Ajax.Net extenstions and framework in order
      to assimilate it wisely in my woring on web application. In general the .NET guys
      did here great job, created here realy a whole framework that includes new controls,
      namespaces etc... The outcome of it is good, it supplies us what we want doing
      it in quite easy way, there are nice webcasts, tutorials and lots of documentation
      that explains how to use it, but it's has also a (little?) disadventage - the actions'
      performance are quite bad in comparison to other open source tools, like <a href="http://www.anthemdotnet.com/" target="_blank">Anthem.Net</a> and
      more, you can impress of it <a href="http://www.daniel-zeiss.de/AJAXComparison/Results.htm" target="_blank">here</a>.
   </p>
        <p>
          <em>Until here is the post's intro... ;)</em>
        </p>
        <p>
      I investigated some the UpdateProgress control, it is nice one and supplies great
      usage and can gives us great UI results in a few minutes of simple actions. By investigating
      the source code of a web page that uses this control, I resolves this related code:
   </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&lt;script
      type=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"text/javascript"</span>&gt;<br />
      &lt;!--<br />
      Sys.Application.initialize();<br />
      Sys.Application.add_init(function() {<br />
      $create(Sys.UI._UpdateProgress, {<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"associatedUpdatePanelId"</span>:<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>,<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"displayAfter"</span>:500,<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"dynamicLayout"</span>:<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">true</span>}, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>,
      $get&lt;Update_Progress_Control_Client_ID&gt;));<br />
      });<br /><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
      --&gt;</span><br />
      &lt;/script&gt;</span>
        </p>
        <p>
      It's nice and being generated automatically of course, but what if you need to do
      some more actions while the callback action is under progress (you can think of tons
      client side actions, right?).
   </p>
        <p>
      In this case I would suggest to abandon the UPdateProgress (great!) control and to
      implement this action by yourself in javascript using the Ajax client-side API, take
      a look of this one:
   </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&lt;script
      type=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"text/javascript"</span>&gt;<br />
          Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(<br />
              function ()<br />
              {<br />
                  <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
      Do your actions...        <br />
              }</span><br />
          );<br />
          <br />
          Sys.WebForms.PageRequestManager.getInstance().add_endRequest(<br />
              function ()<br />
              {<br />
                  <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
      Do your actions...</span><br />
              }<br />
          );<br />
      &lt;/script&gt;</span>
        </p>
        <p>
      Using the <a href="http://www.asp.net/AJAX/Documentation/Live/ClientReference/Sys.WebForms/PageRequestManagerClass/default.aspx" target="_blank">Sys.WebForms.PageRequestManager</a> object,
      you can add/remove handlers to the <a href="http://www.asp.net/AJAX/Documentation/Live/overview/AJAXClientEvents.aspx" target="_blank">Ajax
      client-side Life-Cycle events</a> and do your stuff in a focused and single place
      -&gt; much more easier to handle and to maintain.
   </p>
        <img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=a23b7e24-df2c-4305-9bbd-b6a90fc6b4e0" />
      </body>
      <title>I would give up the UpdateProgress Ajax.Net Control (Sometimes...)</title>
      <guid>http://www.eranachum.com/PermaLink,guid,a23b7e24-df2c-4305-9bbd-b6a90fc6b4e0.aspx</guid>
      <link>http://www.eranachum.com/PermaLink,guid,a23b7e24-df2c-4305-9bbd-b6a90fc6b4e0.aspx</link>
      <pubDate>Wed, 10 Oct 2007 14:41:44 GMT</pubDate>
      <description>&lt;p&gt;
   Lately I am focusing more and more on the Ajax.Net extenstions and framework in order
   to assimilate it wisely in my woring on web application. In general the .NET guys
   did here great job, created here realy&amp;nbsp;a whole framework that includes new controls,
   namespaces etc... The outcome of it is good, it supplies&amp;nbsp;us what we want doing
   it in quite easy way, there are nice webcasts, tutorials and lots of documentation
   that explains how to use it, but it's has also a (little?) disadventage - the actions'
   performance are quite bad in comparison to other open source tools, like &lt;a href="http://www.anthemdotnet.com/" target=_blank&gt;Anthem.Net&lt;/a&gt; and
   more, you can impress of it &lt;a href="http://www.daniel-zeiss.de/AJAXComparison/Results.htm" target=_blank&gt;here&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
   &lt;em&gt;Until here is the post's intro... ;)&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
   I investigated some the UpdateProgress control, it is nice one and supplies great
   usage and can gives us great UI results in a few minutes of simple actions. By investigating
   the source code of a web page that uses this control, I resolves this related code:
&lt;/p&gt;
&lt;p&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;lt;script
   type=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"text/javascript"&lt;/span&gt;&amp;gt;&lt;br&gt;
   &amp;lt;!--&lt;br&gt;
   Sys.Application.initialize();&lt;br&gt;
   Sys.Application.add_init(function() {&lt;br&gt;
   $create(Sys.UI._UpdateProgress, {&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"associatedUpdatePanelId"&lt;/span&gt;:&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;null&lt;/span&gt;,&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"displayAfter"&lt;/span&gt;:500,&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"dynamicLayout"&lt;/span&gt;:&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;true&lt;/span&gt;}, &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;null&lt;/span&gt;, &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;null&lt;/span&gt;,
   $get&amp;lt;Update_Progress_Control_Client_ID&amp;gt;));&lt;br&gt;
   });&lt;br&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
   --&amp;gt;&lt;/span&gt;
   &lt;br&gt;
   &amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
   It's nice and being generated automatically of course, but what if you need to do
   some more actions while the callback action is under progress (you can think of tons
   client side actions, right?).
&lt;/p&gt;
&lt;p&gt;
   In this case I would suggest to abandon the UPdateProgress (great!) control and to
   implement this action by yourself in javascript using the Ajax client-side API, take
   a look of this one:
&lt;/p&gt;
&lt;p&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;lt;script
   type=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"text/javascript"&lt;/span&gt;&amp;gt;&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;function ()&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
   Do your actions...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;
   &lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Sys.WebForms.PageRequestManager.getInstance().add_endRequest(&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;function ()&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
   Do your actions...&lt;/span&gt;
   &lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);&lt;br&gt;
   &amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
   Using the &lt;a href="http://www.asp.net/AJAX/Documentation/Live/ClientReference/Sys.WebForms/PageRequestManagerClass/default.aspx" target=_blank&gt;Sys.WebForms.PageRequestManager&lt;/a&gt; object,
   you can add/remove&amp;nbsp;handlers to the &lt;a href="http://www.asp.net/AJAX/Documentation/Live/overview/AJAXClientEvents.aspx" target=_blank&gt;Ajax
   client-side Life-Cycle events&lt;/a&gt; and do your stuff in a focused and single place
   -&amp;gt; much more easier to handle and to maintain.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=a23b7e24-df2c-4305-9bbd-b6a90fc6b4e0" /&gt;</description>
      <category>AJAX;ASP.NET</category>
    </item>
    <item>
      <trackback:ping>http://www.eranachum.com/Trackback.aspx?guid=fff4a4f5-129b-4e90-a0de-11bc2a8bac9d</trackback:ping>
      <pingback:server>http://www.eranachum.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.eranachum.com/PermaLink,guid,fff4a4f5-129b-4e90-a0de-11bc2a8bac9d.aspx</pingback:target>
      <dc:creator>eranachum@hotmail.com (Eran Nachum)</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
      I wouldn't call it a problem/error/bug/you can call it how you want, I'll call it
      a moment of idiotic lack of attention?
   </p>
        <p>
      I struggled with a very common problem (it seems to be a common after some googling): <em>"My
      Global.asax events are not being constructed/called - what should I do?";</em> this
      one was so familiar and I was sure that I've done everything like it has to be, so
      again what was it?
   </p>
        <p>
      Finally I figured out my problem myself and was supprised of it (I'm seriously not
      jocking), the Global.asax file was not placed under the root folder of my web application
      (my web aplication structure is quite 'complex' because it suppose to serve many web
      sites that sits also in the same solution). I replaced it in the right folder (the
      one that the IIS is pointed to) and that's it.
   </p>
        <p>
      I think that post can solve to (starter?) web developers this (common?) problem while
      it occurs, because google's results didn't supply very good solutions for
      this one.
   </p>
        <p>
      What aobut me? Even after developing and designing many web applications, things like
      that could happen to anyone :-S
   </p>
        <img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=fff4a4f5-129b-4e90-a0de-11bc2a8bac9d" />
      </body>
      <title>Don't forget to put your Global.asax in the right place, errr....</title>
      <guid>http://www.eranachum.com/PermaLink,guid,fff4a4f5-129b-4e90-a0de-11bc2a8bac9d.aspx</guid>
      <link>http://www.eranachum.com/PermaLink,guid,fff4a4f5-129b-4e90-a0de-11bc2a8bac9d.aspx</link>
      <pubDate>Mon, 08 Oct 2007 12:42:52 GMT</pubDate>
      <description>&lt;p&gt;
   I wouldn't call it a problem/error/bug/you can call it how you want, I'll call it
   a moment of idiotic lack of attention?
&lt;/p&gt;
&lt;p&gt;
   I struggled with a very common problem (it seems to be a common after some googling): &lt;em&gt;"My
   Global.asax events are not being constructed/called - what should I do?";&lt;/em&gt; this
   one was so familiar and I was sure that I've done everything like it has to be, so
   again what was it?
&lt;/p&gt;
&lt;p&gt;
   Finally I figured out my problem myself and was supprised of it (I'm seriously not
   jocking), the Global.asax file was not placed under the root folder of my web application
   (my web aplication structure is quite 'complex' because it suppose to serve many web
   sites that sits also in the same solution). I replaced it in the right folder (the
   one that the IIS is pointed to) and that's it.
&lt;/p&gt;
&lt;p&gt;
   I think that post can solve to (starter?) web developers this (common?) problem while
   it occurs, because google's results didn't supply&amp;nbsp;very good solutions&amp;nbsp;for
   this one.
&lt;/p&gt;
&lt;p&gt;
   What aobut me? Even after developing and designing many web applications, things like
   that could happen to anyone :-S
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=fff4a4f5-129b-4e90-a0de-11bc2a8bac9d" /&gt;</description>
      <category>ASP.NET;Bugs;Life</category>
    </item>
    <item>
      <trackback:ping>http://www.eranachum.com/Trackback.aspx?guid=36f9e516-2473-4cc8-8901-052f07408d07</trackback:ping>
      <pingback:server>http://www.eranachum.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.eranachum.com/PermaLink,guid,36f9e516-2473-4cc8-8901-052f07408d07.aspx</pingback:target>
      <dc:creator>eranachum@hotmail.com (Eran Nachum)</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
      As I posted in the last post, I didn't have much time to update my blog last month
      (even most of this month), so I hope I could catch up these days and post some more
      about the on going issues that comes up.
   </p>
        <p>
      Last month, a gut named <strong>Roni Schuetz</strong> send me an email regarding my
      post about <em>Maintaining Data over Multi-Servers (Load Balancing on Web Farm) </em>(direct
      link <a href="http://www.eranachum.com/PermaLink,guid,e62a855a-3633-41f7-842f-a3e9d5f4d5dd.aspx">here</a>).<br />
      Roni is the creator of a project named, Shared Cache which supplies high-performance,
      distributed memory object caching system, generic in nature, but intended to speeding
      up dynamic web and / or win applications by alleviating database load. He suggested
      me to use his project regarding maintaining cached data between multiple servers and
      I acceded testing it.
   </p>
        <p>
      By Roni's documentation and project usage explanations the project is friendly
      usable and for a free-to-use-software I think it is highly recomended using it (or
      at least testing it).
   </p>
        <p>
      Unfortunatly (or not), my company (<a href="http://www.idtglobal.com/" target="_blank">IDT
      Global</a>) has purchased (an expensive and also a great one) tool called <a href="http://www.scaleoutsoftware.com/" target="_blank">ScaleOut
      SessionState</a> In order to maintain session data over multiplae servers.
   </p>
        <p>
      So, if you have an answer regarding this issue or just want to read about it, you
      can try Roni's indeXus.Net Shared Cache <a href="http://www.codeplex.com/SharedCache" target="_blank">here</a>.<br /></p>
        <img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=36f9e516-2473-4cc8-8901-052f07408d07" />
      </body>
      <title>indeXus.Net Shared Cache By Roni Schuetz </title>
      <guid>http://www.eranachum.com/PermaLink,guid,36f9e516-2473-4cc8-8901-052f07408d07.aspx</guid>
      <link>http://www.eranachum.com/PermaLink,guid,36f9e516-2473-4cc8-8901-052f07408d07.aspx</link>
      <pubDate>Mon, 24 Sep 2007 08:15:21 GMT</pubDate>
      <description>&lt;p&gt;
   As I posted in the last post, I didn't have much time to update my blog last month
   (even most of this month), so I hope I could catch up these days and post some more
   about the on going issues that comes up.
&lt;/p&gt;
&lt;p&gt;
   Last month, a gut named &lt;strong&gt;Roni Schuetz&lt;/strong&gt; send me an email regarding my
   post about&amp;nbsp;&lt;em&gt;Maintaining Data over Multi-Servers (Load Balancing on Web Farm) &lt;/em&gt;(direct
   link &lt;a href="http://www.eranachum.com/PermaLink,guid,e62a855a-3633-41f7-842f-a3e9d5f4d5dd.aspx"&gt;here&lt;/a&gt;).&lt;br&gt;
   Roni is the creator of a project named, Shared Cache which supplies high-performance,
   distributed memory object caching system, generic in nature, but intended to speeding
   up dynamic web and / or win applications by alleviating database load. He suggested
   me to use his project regarding maintaining cached data between multiple servers and
   I acceded testing it.
&lt;/p&gt;
&lt;p&gt;
   By Roni's documentation and project usage explanations&amp;nbsp;the project is friendly
   usable and for a free-to-use-software I think it is highly recomended&amp;nbsp;using it&amp;nbsp;(or
   at least testing it).
&lt;/p&gt;
&lt;p&gt;
   Unfortunatly (or not), my company (&lt;a href="http://www.idtglobal.com/" target=_blank&gt;IDT
   Global&lt;/a&gt;) has purchased (an expensive and also a great one) tool called &lt;a href="http://www.scaleoutsoftware.com/" target=_blank&gt;ScaleOut
   SessionState&lt;/a&gt;&amp;nbsp;In order to maintain session data over multiplae servers.
&lt;/p&gt;
&lt;p&gt;
   So, if you have an answer regarding this issue or just want to read about it, you
   can try Roni's indeXus.Net Shared Cache &lt;a href="http://www.codeplex.com/SharedCache" target=_blank&gt;here&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;
&gt;&lt;img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=36f9e516-2473-4cc8-8901-052f07408d07" /&gt;</description>
      <category>.NET 2005;ASP.NET;System</category>
    </item>
    <item>
      <trackback:ping>http://www.eranachum.com/Trackback.aspx?guid=e62a855a-3633-41f7-842f-a3e9d5f4d5dd</trackback:ping>
      <pingback:server>http://www.eranachum.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.eranachum.com/PermaLink,guid,e62a855a-3633-41f7-842f-a3e9d5f4d5dd.aspx</pingback:target>
      <dc:creator>eranachum@hotmail.com (Eran Nachum)</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
      Every site (or site admin in that case) desires to serve the users that are visiting
      the site on the best way, handle the traffic situation on the best side (if doesn't
      it's annoying the user and there is a chance that they won't come again).
   </p>
        <p>
      Well known solution to this problem is to hold two (or more) servers needed to handle
      user requests. The main idea behind this web farm is to share pooled resources. There
      is a need to hold a common front end dispatcher to perform load control and manage
      customer requests.
   </p>
        <p>
      My working web application answers these criterions mentioned above, it should
      be serving hugh amount of clients, therefore there is a usage of multi servers to
      give the best outcome, and I had to deal with that situation...
   </p>
        <p>
      There several approach to deal this 'problem' that I could think of and listed ahead:
   </p>
        <p>
          <strong>
            <u>Session Management</u>
          </strong>
        </p>
        <p>
      There are 2 solutions supplied by ASP.NET regarding sharing state information between
      multiple servers:<br /><strong>State Server - </strong>In the specific web farm, you must approve that each
      web server holds the same &lt;machinekey&gt;. On the second step, if we'll want to
      maintain the session state across the web servers, each website's application path
      in the IIS metabase should be the same in the web farm.<br />
      One more important thing is to make sure of all the objects should (that you want
      to store in the session of course) be serializable (<a href="http://www.eranachum.com/PermaLink,guid,295cdfb4-d9d0-4362-8787-9eb80703d13b.aspx">remember
      previuos post?</a>).
   </p>
        <p>
          <strong>SQL Server </strong>- Although I am using Oracle Database to store the
      current application data, I just wanted to mention this solution and will expand some
      basic details about this solution; Firstable, you should make sure all the objects
      are serializable, and like before, each website's application path in the IIS
      metabase should be the same in the web farm. This solution requires some SQL Server
      configuration in order to maintain the session management. You can read about it in
      more details <a href="http://support.microsoft.com/kb/317604" target="_blank">here</a> and <a href="http://idunno.org/articles/277.aspx" target="_blank">here</a>.
      Some very important <u>security</u> issues that you must consider are:
   </p>
        <ul>
          <li>
         Don't forget to encrypt your connection string (stored in the web.config or somewhere
         else). 
      </li>
          <li>
         Use Windows authentication to the database and limit the application's login in it. 
      </li>
          <li>
         Run the application in a secure channel.</li>
        </ul>
        <p>
          <strong>
            <u>Machine Authentication Check (MAC)</u>
          </strong>
        </p>
        <p>
      This solution comes for maintaining the form's information after firing events that
      are causing server postback. If you are working on one webserver, well... everything
      will act just fine; A common user behavior will fire a postback event which
      will go back to the server and deal with the sent data. <u>BUT</u>, what will happen
      if the event's data will be posted to another webserver? (All data will be lost...)
   </p>
        <p>
      To solve this 'problem' you should modify the <em>pages</em> element
      in the machine.config of each webserver and set the <em>enableViewStateMac</em> attribute:
   </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&lt;system.web&gt; <br />
         &lt;pages enableViewStateMac=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"false"</span> /&gt; 
      <br />
      &lt;/system.web&gt;</span>
        </p>
        <p>
      This will mention that the process should run a machine authentication check (MAC)
      on the pages' view state when the page is posted back from the client; <strong>true</strong> if
      the view state should be MAC checked and encoded; otherwise, <b>false</b>. The default
      is <strong>false. 
      <br /></strong>"<em>A view state MAC is an encoded version of the hidden variable that a
      page's view state is persisted to when sent to the browser. When you set the <b>EnableViewStateMac</b> attribute
      to <b>true</b>, the encoded and encrypted view state is checked to verify that it
      has not been tampered with on the client.</em>" (from MSDN).
   </p>
        <p>
          <strong>
            <u>Data Caching</u>
          </strong>
        </p>
        <ul>
          <li>
            <strong>Shared Cache Application -</strong>You should use a cache application in order
         to cache you application's data. A good solution is to create am application that
         will be place in a single location. Each application (or each webserver) will send
         its data to this cache application to be cached. Each data retrieval will requested
         from the cache apllication firstly, otherwise will grab it from the specific data
         source (database etc...).</li>
          <li>
            <strong>SQL Server Caching - </strong>You can cache the data into Sql Server, it's
         quite easy to apply using ADO.NET and the .NET Framework provides a common development
         model to use with existing data access components. You can read some details about
         it <a href="http://www.c-sharpcorner.com/UploadFile/mosessaur/sqlcachedependency01292006135138PM/sqlcachedependency.aspx?ArticleID=3caa7d32-dce0-44dc-8769-77f8448e76bc" target="_blank">here</a>.
         Since in most case there is a single database that holds the data, you can use this
         kind of solution.</li>
        </ul>
        <p>
      These are some of the ways for maintaining data over multi servers. I will be glad
      to hear about some more solutions and ways...
   </p>
        <img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=e62a855a-3633-41f7-842f-a3e9d5f4d5dd" />
      </body>
      <title>Maintaining Data over Multi-Servers (Load Balancing on Web Farm)</title>
      <guid>http://www.eranachum.com/PermaLink,guid,e62a855a-3633-41f7-842f-a3e9d5f4d5dd.aspx</guid>
      <link>http://www.eranachum.com/PermaLink,guid,e62a855a-3633-41f7-842f-a3e9d5f4d5dd.aspx</link>
      <pubDate>Mon, 13 Aug 2007 06:07:55 GMT</pubDate>
      <description>&lt;p&gt;
   Every site (or site admin in that case) desires to serve the&amp;nbsp;users that are visiting
   the site on the best way, handle the traffic situation on the best side (if doesn't
   it's annoying the user and there is a chance that they won't come again).
&lt;/p&gt;
&lt;p&gt;
   Well known solution to this problem is to hold two (or more) servers needed to handle
   user requests. The main idea behind this web farm is to share pooled resources. There
   is a need to hold a common front end dispatcher to perform load control and manage
   customer requests.
&lt;/p&gt;
&lt;p&gt;
   My working web application&amp;nbsp;answers&amp;nbsp;these criterions mentioned above, it&amp;nbsp;should
   be serving hugh amount of clients, therefore there is a usage of multi servers to
   give the best outcome, and I had to deal with that situation...
&lt;/p&gt;
&lt;p&gt;
   There several approach to deal this 'problem' that I could think of and listed ahead:
&lt;/p&gt;
&lt;p&gt;
   &lt;strong&gt;&lt;u&gt;Session Management&lt;/u&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
   There are 2 solutions supplied by ASP.NET regarding sharing state information between
   multiple servers:&lt;br&gt;
   &lt;strong&gt;State Server - &lt;/strong&gt;In the specific web farm, you must approve that each
   web server holds the same &amp;lt;machinekey&amp;gt;. On the second step, if we'll want to
   maintain the session state across the web servers, each website's application path
   in the IIS metabase should be the same in the web farm.&lt;br&gt;
   One more important thing is to make sure of all the objects should (that you want
   to store in the session of course) be serializable (&lt;a href="http://www.eranachum.com/PermaLink,guid,295cdfb4-d9d0-4362-8787-9eb80703d13b.aspx"&gt;remember
   previuos post?&lt;/a&gt;).
&lt;/p&gt;
&lt;p&gt;
   &lt;strong&gt;SQL&amp;nbsp;Server &lt;/strong&gt;- Although I am using Oracle Database to store the
   current application data, I just wanted to mention this solution and will expand some
   basic details about this solution; Firstable, you should make sure all the objects
   are serializable, and&amp;nbsp;like before, each website's application path in the IIS
   metabase should be the same in the web farm. This solution requires some SQL Server
   configuration in order to maintain the session management. You can read about it in
   more details &lt;a href="http://support.microsoft.com/kb/317604" target=_blank&gt;here&lt;/a&gt; and &lt;a href="http://idunno.org/articles/277.aspx" target=_blank&gt;here&lt;/a&gt;.
   Some very important &lt;u&gt;security&lt;/u&gt; issues that you must consider are:
&lt;/p&gt;
&lt;ul&gt;
   &lt;li&gt;
      Don't forget to encrypt your connection string (stored in the web.config or somewhere
      else). 
   &lt;li&gt;
      Use Windows authentication to the database and limit the application's login in it. 
   &lt;li&gt;
      Run the application in a secure channel.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
   &lt;strong&gt;&lt;u&gt;Machine Authentication Check (MAC)&lt;/u&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
   This solution comes for maintaining the form's information after firing events that
   are causing server postback. If you are working on one webserver, well... everything
   will act just fine;&amp;nbsp;A common&amp;nbsp;user behavior will fire a postback event which
   will go back to the server and deal with the sent data. &lt;u&gt;BUT&lt;/u&gt;, what will happen
   if the event's data will be posted to another webserver? (All data will be lost...)
&lt;/p&gt;
&lt;p&gt;
   To solve this 'problem' you should&amp;nbsp;modify&amp;nbsp;the &lt;em&gt;pages&lt;/em&gt;&amp;nbsp;element
   in the machine.config of each webserver and set the &lt;em&gt;enableViewStateMac&lt;/em&gt; attribute:
&lt;/p&gt;
&lt;p&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;lt;system.web&amp;gt;&amp;nbsp;&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;pages enableViewStateMac=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"false"&lt;/span&gt; /&amp;gt; 
   &lt;br&gt;
   &amp;lt;/system.web&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
   This will mention that the process should run a machine authentication check (MAC)
   on the pages' view state when the page is posted back from the client; &lt;strong&gt;true&lt;/strong&gt; if
   the view state should be MAC checked and encoded; otherwise, &lt;b&gt;false&lt;/b&gt;. The default
   is &lt;strong&gt;false. 
   &lt;br&gt;
   &lt;/strong&gt;"&lt;em&gt;A view state MAC is an encoded version of the hidden variable that a
   page's view state is persisted to when sent to the browser. When you set the &lt;b&gt;EnableViewStateMac&lt;/b&gt; attribute
   to &lt;b&gt;true&lt;/b&gt;, the encoded and encrypted view state is checked to verify that it
   has not been tampered with on the client.&lt;/em&gt;" (from MSDN).
&lt;/p&gt;
&lt;p&gt;
   &lt;strong&gt;&lt;u&gt;Data Caching&lt;/u&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;ul&gt;
   &lt;li&gt;
      &lt;strong&gt;Shared Cache Application -&lt;/strong&gt;You should use a cache application in order
      to cache you application's data. A good solution is to create am application that
      will be place in a single location. Each application (or each webserver) will send
      its data to this cache application to be cached. Each data retrieval will requested
      from the cache apllication firstly, otherwise will grab it from the specific data
      source (database etc...).&lt;/li&gt;
   &lt;li&gt;
      &lt;strong&gt;SQL Server Caching - &lt;/strong&gt;You can cache the data into Sql Server, it's
      quite easy to apply using ADO.NET and the .NET Framework provides a common development
      model to use with existing data access components. You can read some details about
      it &lt;a href="http://www.c-sharpcorner.com/UploadFile/mosessaur/sqlcachedependency01292006135138PM/sqlcachedependency.aspx?ArticleID=3caa7d32-dce0-44dc-8769-77f8448e76bc" target=_blank&gt;here&lt;/a&gt;.
      Since in most case there is a single database that holds the data, you can use this
      kind of solution.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
   These are some of the ways for maintaining data over multi servers. I will be glad
   to hear about some more solutions and ways...
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=e62a855a-3633-41f7-842f-a3e9d5f4d5dd" /&gt;</description>
      <category>ASP.NET</category>
    </item>
    <item>
      <trackback:ping>http://www.eranachum.com/Trackback.aspx?guid=295cdfb4-d9d0-4362-8787-9eb80703d13b</trackback:ping>
      <pingback:server>http://www.eranachum.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.eranachum.com/PermaLink,guid,295cdfb4-d9d0-4362-8787-9eb80703d13b.aspx</pingback:target>
      <dc:creator>eranachum@hotmail.com (Eran Nachum)</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <em>
            <strong>Post Prolog:</strong>
          </em>Out of the record, as a continues to the previous
      post, I want to say that I am enjoing my life as a father, if I had know it I would
      do it earlier, BTW the little one named by my wife and me as <strong>Ori. </strong>More
      pics will be publish soon...)
   </p>
        <p>
      Now, to this post issue...
   </p>
        <p>
      I bumped in on a strange scenario; In my current working application, I have a
      page that holds a repeater that displays some data. This data is being declared in
      each partner's web.config's configSection. In order to read it once, I set this custom
      object as a Serializable one (which implements the ISerializable interface of
      course) and saved it into the ViewState of the page.
   </p>
        <p>
      Now, when reading this object and saving it into the ViewState, everything has
      worked just fine (the server serialized this data properly).<br />
      But, when trying to grab this data from the ViewState (de-serialize this data) an
      annoying and vauge error message has been displayed was saying that: "<em>The state
      information is invalid for this page and might be corrupted</em>". 
   </p>
        <p>
      After a long and frustrating research about it, it turns out that the server
      will have <strong>NO KNOWLEDGE</strong> of the assembly name (Note: It was randomly
      generated when your <i>site </i>compiled on first run) because its own version of
      that assembly will have been compiled with a completely different random name, and
      it will not be able to de-serialise the viewstate and get the requested data.
   </p>
        <p>
      To get around this problem, we should <strong>AVOID PLACING </strong>custom types
      into the viewstate (place'em somewhere else, like session, application etc.).
   </p>
        <p>
      If you've got some more complex objects (or some custom types), these will need to
      be moved into a seperate class library project that is pre-compiled before deploying
      to the web-server. By doing it, it can be ensured that every web server has a copy
      of the same assembly and that the assembly has the <b>same signature/name!  </b>Try
      to avoid creating custom types in your App_Code or any of your web <i>site</i> files. 
      Rather create custom types in their own project to be compiled into a seperate assembly.
   </p>
        <p>
      Cheers by now...
   </p>
        <img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=295cdfb4-d9d0-4362-8787-9eb80703d13b" />
      </body>
      <title>Should we always place custom types / objects in ViewState?</title>
      <guid>http://www.eranachum.com/PermaLink,guid,295cdfb4-d9d0-4362-8787-9eb80703d13b.aspx</guid>
      <link>http://www.eranachum.com/PermaLink,guid,295cdfb4-d9d0-4362-8787-9eb80703d13b.aspx</link>
      <pubDate>Mon, 06 Aug 2007 12:25:07 GMT</pubDate>
      <description>&lt;p&gt;
   &lt;em&gt;&lt;strong&gt;Post Prolog:&lt;/strong&gt; &lt;/em&gt;Out of the record, as a continues to the previous
   post, I want to say that I am enjoing my life as a father, if I had know it I would
   do it earlier, BTW the little one named by my wife and me as &lt;strong&gt;Ori. &lt;/strong&gt;More
   pics will be publish soon...)
&lt;/p&gt;
&lt;p&gt;
   Now, to this post issue...
&lt;/p&gt;
&lt;p&gt;
   I bumped in on a strange scenario; In my current working application, I have&amp;nbsp;a
   page that holds a repeater that displays some data. This data is being declared in
   each partner's web.config's configSection. In order to read it once, I set this custom
   object as&amp;nbsp;a Serializable one (which implements the ISerializable interface of
   course) and saved it into the ViewState of the page.
&lt;/p&gt;
&lt;p&gt;
   Now, when reading this object and saving it into the ViewState, everything&amp;nbsp;has
   worked just fine&amp;nbsp;(the server serialized this data properly).&lt;br&gt;
   But, when trying to grab this data from the ViewState (de-serialize this data) an
   annoying and vauge error message has been displayed was saying that: "&lt;em&gt;The state
   information is invalid for this page and might be corrupted&lt;/em&gt;". 
&lt;/p&gt;
&lt;p&gt;
   After a long and frustrating research about it, it turns out that the&amp;nbsp;server
   will have &lt;strong&gt;NO KNOWLEDGE&lt;/strong&gt; of the assembly name (Note: It was&amp;nbsp;randomly
   generated when your &lt;i&gt;site &lt;/i&gt;compiled on first run) because its own version of
   that assembly will have been compiled with a completely different random name, and
   it will not be able to de-serialise the viewstate and get the requested data.
&lt;/p&gt;
&lt;p&gt;
   To get around this problem, we should &lt;strong&gt;AVOID PLACING &lt;/strong&gt;custom types
   into the viewstate (place'em somewhere else, like session, application etc.).
&lt;/p&gt;
&lt;p&gt;
   If you've got some more complex objects (or some custom types), these will need to
   be moved into a seperate class library project that is pre-compiled before deploying
   to the web-server. By doing it, it can be ensured that every web server has a copy
   of the same assembly and that the assembly has the &lt;b&gt;same signature/name!&amp;nbsp; &lt;/b&gt;Try
   to avoid creating custom types in your App_Code or any of your web &lt;i&gt;site&lt;/i&gt; files.&amp;nbsp;
   Rather create custom types in their own project to be compiled into a seperate assembly.
&lt;/p&gt;
&lt;p&gt;
   Cheers by now...
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=295cdfb4-d9d0-4362-8787-9eb80703d13b" /&gt;</description>
      <category>ASP.NET;Bugs</category>
    </item>
    <item>
      <trackback:ping>http://www.eranachum.com/Trackback.aspx?guid=532c3302-dde3-4abd-a652-1864b13cf8b4</trackback:ping>
      <pingback:server>http://www.eranachum.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.eranachum.com/PermaLink,guid,532c3302-dde3-4abd-a652-1864b13cf8b4.aspx</pingback:target>
      <dc:creator>eranachum@hotmail.com (Eran Nachum)</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
      I am working against 3rd level party assembly in my current web application. I need
      to send US address information to this assembly and to retrieve an answer whether
      this address is exist or not. This assembly requires validation against X.509 certificate
      (to ensure that only permited client could use the 3rd level's services), which is
      installed on the server that runs the application (in dev environment this is my local
      PC). 
      <br />
      More details about it <a href="http://www.codeproject.com/useritems/X509Certificate.asp" target="_blank">here</a>.
   </p>
        <p>
          <strong>The problem:</strong> In order to authenticate against this certificate, the
      process that runs the application need to 'hold' sufficient credentials in order to
      get an access to the certificate and to do the authentication. Here comes our problem;
      when trying to access this certificate through the asp.net application, we run into
      a problem - It's impossible, because the process that runs the web application is
      ASPNET and doesn't has the needed credentials in order to authenticate the certificate
      and get the info from the 3rd level.
   </p>
        <p>
          <strong>Suggested solutions:<br /></strong>
        </p>
        <ol>
          <li>
            <strong>Credentials</strong>. Read the credentials from the web.config (username,
         password and domain) and impersonate the user using these credentials. This will
         'save' the impersonated user all over the impersonation context (<font size="2">System.Security.Principal.WindowsImpersonationContext</font>)
         and the authenicate action against the certificate will be done using this credentials.
         One more important thing, to ensure this data protected, encrypt it before puting
         it into the web.config. 
      </li>
          <li>
         I thought about <strong>IIS Application Pool.</strong> This is a great feature that
         came up in IIS 6.0, which enables you the ability of creating one or more applications
         and allows us to configure a level of isolation between different Web applications.
         You can set the identity of an application pool which will be the account under which
         the application pool's worker process runs. So I thought to set it over there, but
         I had one big problem, an IIS 5 was installed on the production server and it is not
         a dedicated server. (More details about application pool <a href="http://www.developer.com/net/asp/article.php/2245511" target="_blank">here</a>). 
      </li>
          <li>
            <strong>Host .NET component in COM+</strong>. This is the third solution and the best
         for me at the current circumstances; Because I am working with a several applications
         (assemblies) I want to host the component that validates the user against the
         3rd level party, this will give me a unified behavoir for all the applications while
         doing this action (Instead of setting these properties in web.config file of
         each web application we want to use {solution 1, remember?}). In other words,
         I'll set the username and password on the COM+ component just once in order to grant
         the process that runs this component the right and sufficient credentials. .NET
         provides a way to host your .NET components inside COM+ environment. All the functionality
         you need to write a COM+ aware component in .NET can be found in System.EnterpriseServices
         namespace.</li>
        </ol>
        <p>
          <strong>So how we do it (hosting .NET assembly in COM+)?</strong>
        </p>
        <p>
      Take a look on this code:
   </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</span> System;<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</span> System.Collections.Generic;<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</span> System.Text;<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</span> System.EnterpriseServices;<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</span> System.IO;<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</span> System.Reflection;<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</span> System.Runtime.InteropServices;<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">namespace</span> ComPlusTest<br />
      {<br />
          [Transaction(TransactionOption.Required), 
      <br />
              ObjectPooling(MinPoolSize=2, MaxPoolSize=5,
      CreationTimeout=20000),<br />
              ComVisible(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">true</span>)]<br />
          <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> TestClass
      : ServicedComponent<br />
          {<br />
              <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">protected</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">override</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> Activate()<br />
              {<br />
                  <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">base</span>.Activate();<br />
                  DoSomeAction(Action
      activate)<br />
              }<br /><br />
              <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">protected</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">override</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> Deactivate()<br />
              {<br />
                  <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">base</span>.Deactivate();<br />
                  DoSomeAction(Action
      deactivate)<br />
              }<br /><br />
              <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">protected</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">override</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">bool</span> CanBePooled()<br />
              {<br />
                  DoSomeAction(Action
      pooled)<br />
                  <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">return</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">base</span>.CanBePooled();<br />
              }</span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">        <font color="#0000ff">public
      void</font> ValidateAddress(<font color="#0000ff">string</font> address)<br />
              {<br />
                  <font color="#0000ff">try</font><br />
                  {<br />
                     //
      Do the validation against the 3rd party<br />
                     ContextUtil.SetComplete();<br />
                  }<br />
                  <font color="#0000ff">catch</font>(Exception
      ex)<br />
                  {<br />
                     //
      Handle exception<br />
                     ContextUtil.SetAbort();<br />
                  }<br />
              }<br /></span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <br />
              [AutoComplete()]<br />
              <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> JustAction()<br />
              {<br />
                  DoSomeAction(Action
      simpleAction);<br />
              }<br /><br />
              <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">private</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> DoSomeAction(Action
      act)<br />
              {<br />
                  <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
      Do the action</span><br />
              }<br />
          }<br />
      }<br /></span>
        </p>
        <p>
      Lets dissect it:
   </p>
        <ol>
          <li>
         Firstable you can see that the class is derived from ServicesComponent (which sits
         in the System.EnterpriseServices namespace). I marked our TestClass with some attributes.
         The first one in Transaction; The values for this attribute are same as in traditional
         VB/VC++ development i.e. Required, RequiresNew, Supported etc. MinPoolSize and MaxPoolSize
         specifies values for minimum and maximum object instances. The ComVisible attribute <strong>must </strong>be
         set to true to give the accessibility of an individual managed type or member, or
         of all types within an assembly, to COM (I spent lots of time trying to figure out
         some exceptions that I had while overriding the ServicesComponent class). 
      </li>
          <li>
         the class is marked to require a transaction each method will execute in a transaction
         (existing or new). Once the ValidateAddress has been executed we need to either commit
         or rollback the transaction. This is done via static methods of <strong>ContextUtil</strong> class.
         The method <strong>SetComplete</strong> is used to commit a transaction where as SetAbort
         is used to rollback a transaction. 
      </li>
          <li>
         Just for example, I defined a methid called JustAction. This method is marked with
         an attribute <strong>AutoComplete</strong> which means that once the method execution
         is over the transaction is automatically committed (equivalent to ContextUtil.SetComplete).
         In case of any error the transaction will be rolled back (equivalent to ContextUtil.SetAbort). 
      </li>
          <li>
         Overrided Activate, Deactivate and CanBePooled methods are just for testing (in
         order to observe the flow behavior).</li>
        </ol>
        <p>
      Now, you have to sign your assembly with a strong name and to add the following attributes
      to the AssemblyInfo class of your project:
   </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">[assembly:
      ApplicationName(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"ComPlusTest"</span>)]<br />
      [assembly: ApplicationActivation(ActivationOption.Library)]<br />
      [assembly: AssemblyKeyFileAttribute(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"ComPlusKey.pfx"</span>)]</span>
        </p>
        <img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=532c3302-dde3-4abd-a652-1864b13cf8b4" />
      </body>
      <title>Hosting .NET Assembly in COM+ Situation</title>
      <guid>http://www.eranachum.com/PermaLink,guid,532c3302-dde3-4abd-a652-1864b13cf8b4.aspx</guid>
      <link>http://www.eranachum.com/PermaLink,guid,532c3302-dde3-4abd-a652-1864b13cf8b4.aspx</link>
      <pubDate>Tue, 10 Jul 2007 14:49:24 GMT</pubDate>
      <description>&lt;p&gt;
   I am working against 3rd level party assembly in my current web application. I need
   to send US address information to this&amp;nbsp;assembly and to retrieve an answer whether
   this address is exist or not. This assembly requires validation against X.509 certificate
   (to ensure that only permited client could use the 3rd level's services), which is
   installed on the server that runs the application (in dev environment this is my local
   PC). 
   &lt;br&gt;
   More details about it &lt;a href="http://www.codeproject.com/useritems/X509Certificate.asp" target=_blank&gt;here&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
   &lt;strong&gt;The problem:&lt;/strong&gt; In order to authenticate against this certificate, the
   process that runs the application need to 'hold' sufficient credentials in order to
   get an access to the certificate and to do the authentication. Here comes our problem;
   when trying to access this certificate through the asp.net application, we run into
   a problem - It's impossible, because the process that runs the web application is
   ASPNET and doesn't has the needed credentials in order to authenticate the certificate
   and get the info from the 3rd level.
&lt;/p&gt;
&lt;p&gt;
   &lt;strong&gt;Suggested solutions:&lt;br&gt;
   &lt;/strong&gt;
&lt;/p&gt;
&lt;ol&gt;
   &lt;li&gt;
      &lt;strong&gt;Credentials&lt;/strong&gt;. Read the credentials from the web.config (username,
      password and domain) and&amp;nbsp;impersonate the user using these credentials. This will
      'save' the impersonated user all over the&amp;nbsp;impersonation context (&lt;font size=2&gt;System.Security.Principal.WindowsImpersonationContext&lt;/font&gt;)
      and the authenicate action against the certificate will be done using this credentials.
      One more important thing, to ensure this data protected, encrypt it before puting
      it into the web.config. 
   &lt;li&gt;
      I thought about &lt;strong&gt;IIS Application Pool.&lt;/strong&gt; This is a great feature that
      came up in IIS 6.0, which enables you the ability of creating one or more applications
      and allows us to configure a level of isolation between different Web applications.
      You can set the identity of an application pool which will be the account under which
      the application pool's worker process runs. So I thought to set it over there, but
      I had one big problem, an IIS 5 was installed on the production server and it is not
      a dedicated server. (More details about application pool &lt;a href="http://www.developer.com/net/asp/article.php/2245511" target=_blank&gt;here&lt;/a&gt;). 
   &lt;li&gt;
      &lt;strong&gt;Host .NET component in COM+&lt;/strong&gt;. This is the third solution and the best
      for me at the current circumstances; Because I am working with a several&amp;nbsp;applications
      (assemblies) I want to host the&amp;nbsp;component that validates the user against the
      3rd level party, this will give me a unified behavoir for all the applications while
      doing this action (Instead of setting these properties in&amp;nbsp;web.config file of
      each web application we want to use&amp;nbsp;{solution 1, remember?}). In other words,
      I'll set the username and password on the COM+ component just once&amp;nbsp;in order to&amp;nbsp;grant
      the process that runs this component the right and sufficient credentials.&amp;nbsp;.NET
      provides a way to host your .NET components inside COM+ environment. All the functionality
      you need to write a COM+ aware component in .NET can be found in System.EnterpriseServices
      namespace.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
   &lt;strong&gt;So how we do it (hosting .NET assembly in COM+)?&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
   Take a look on this code:
&lt;/p&gt;
&lt;p&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;using&lt;/span&gt; System;&lt;br&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;br&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;using&lt;/span&gt; System.Text;&lt;br&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;using&lt;/span&gt; System.EnterpriseServices;&lt;br&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;using&lt;/span&gt; System.IO;&lt;br&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;using&lt;/span&gt; System.Reflection;&lt;br&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;using&lt;/span&gt; System.Runtime.InteropServices;&lt;br&gt;
   &lt;br&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;namespace&lt;/span&gt; ComPlusTest&lt;br&gt;
   {&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Transaction(TransactionOption.Required), 
   &lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ObjectPooling(MinPoolSize=2, MaxPoolSize=5,
   CreationTimeout=20000),&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ComVisible(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;true&lt;/span&gt;)]&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;class&lt;/span&gt; TestClass
   : ServicedComponent&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;protected&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;override&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; Activate()&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;base&lt;/span&gt;.Activate();&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DoSomeAction(Action
   activate)&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
   &lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;protected&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;override&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; Deactivate()&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;base&lt;/span&gt;.Deactivate();&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DoSomeAction(Action
   deactivate)&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
   &lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;protected&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;override&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;bool&lt;/span&gt; CanBePooled()&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DoSomeAction(Action
   pooled)&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;return&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;base&lt;/span&gt;.CanBePooled();&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=#0000ff&gt;public
   void&lt;/font&gt; ValidateAddress(&lt;font color=#0000ff&gt;string&lt;/font&gt; address)&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=#0000ff&gt;try&lt;/font&gt;
   &lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//
   Do the validation against the 3rd party&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ContextUtil.SetComplete();&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=#0000ff&gt;catch&lt;/font&gt;(Exception
   ex)&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//
   Handle exception&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ContextUtil.SetAbort();&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
   &lt;/span&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;
   &lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[AutoComplete()]&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; JustAction()&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DoSomeAction(Action
   simpleAction);&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
   &lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;private&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; DoSomeAction(Action
   act)&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
   Do the action&lt;/span&gt;
   &lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
   }&lt;br&gt;
&lt;/p&gt;
&gt; 
&lt;p&gt;
   Lets dissect it:
&lt;/p&gt;
&lt;ol&gt;
   &lt;li&gt;
      Firstable you can see that the class is derived from ServicesComponent (which sits
      in the System.EnterpriseServices namespace). I marked our TestClass with some attributes.
      The first one in Transaction; The values for this attribute are same as in traditional
      VB/VC++ development i.e. Required, RequiresNew, Supported etc. MinPoolSize and MaxPoolSize
      specifies values for minimum and maximum object instances. The ComVisible attribute &lt;strong&gt;must &lt;/strong&gt;be
      set to true to give the accessibility of an individual managed type or member, or
      of all types within an assembly, to COM (I spent lots of time trying to figure out
      some exceptions that I had while overriding the ServicesComponent class). 
   &lt;li&gt;
      the class is marked to require a transaction each method will execute in a transaction
      (existing or new). Once the ValidateAddress has been executed we need to either commit
      or rollback the transaction. This is done via static methods of &lt;strong&gt;ContextUtil&lt;/strong&gt; class.
      The method &lt;strong&gt;SetComplete&lt;/strong&gt; is used to commit a transaction where as SetAbort
      is used to rollback a transaction. 
   &lt;li&gt;
      Just for example, I defined a methid called JustAction. This method is marked with
      an attribute &lt;strong&gt;AutoComplete&lt;/strong&gt; which means that once the method execution
      is over the transaction is automatically committed (equivalent to ContextUtil.SetComplete).
      In case of any error the transaction will be rolled back (equivalent to ContextUtil.SetAbort). 
   &lt;li&gt;
      Overrided&amp;nbsp;Activate, Deactivate and CanBePooled methods are just for testing (in
      order to observe the flow behavior).&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
   Now, you have to sign your assembly with a strong name and to add the following attributes
   to the AssemblyInfo class of your project:
&lt;/p&gt;
&lt;p&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;[assembly:
   ApplicationName(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"ComPlusTest"&lt;/span&gt;)]&lt;br&gt;
   [assembly: ApplicationActivation(ActivationOption.Library)]&lt;br&gt;
   [assembly: AssemblyKeyFileAttribute(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"ComPlusKey.pfx"&lt;/span&gt;)]&lt;/span&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=532c3302-dde3-4abd-a652-1864b13cf8b4" /&gt;</description>
      <category>.NET 2005;ASP.NET;Code;System</category>
    </item>
    <item>
      <trackback:ping>http://www.eranachum.com/Trackback.aspx?guid=11f0552d-7bfc-4f1c-9154-f5c391e4b9ee</trackback:ping>
      <pingback:server>http://www.eranachum.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.eranachum.com/PermaLink,guid,11f0552d-7bfc-4f1c-9154-f5c391e4b9ee.aspx</pingback:target>
      <dc:creator>eranachum@hotmail.com (Eran Nachum)</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
      I had a performance problem in my current working on web application; In one of my
      flows in this application, I had needed to call the database and to update some large
      amount of data over there, but this action had taken lots of time and the outcome
      was that users had to wait a long time until this action will be done, admit it, it
      is frustrating...
   </p>
        <p>
      My first kind of solution to this problem was to create a new thred from the IIS's
      thread pool and to assign this action under it - quite good resolution not? BUT,
      I reminded that asp.net 2.0 (also 1.X) already implements it in a better and friendly
      way, using <strong>Asynchronous Pages</strong>.
   </p>
        <p>
          <em>But first, some Background...<br /></em>As we all know (or not), when ASP.NET receives a request from the user, it ask
      for a thread from a thread pool and assigns that request to the thread. In order
      to this action, the synchronous page holds this thread for the duration of the request,
      and preventing it from being used by other requests. That leads us to my problem:
      when I am calling to the database and doing the long long action (an UPDATE query),
      the thread assigned to the request is <strong>stuck</strong> doing nothing until the
      call returns. (This happens because the thread pool has a finite number of threads
      available). 
   </p>
        <p>
          <em>The Resolution is (of course) </em>
          <strong>Asynchronous Pages.</strong>
        </p>
        <p>
      Asynchronous pages offers a neat solution to such kind of problems. Once an asynchronous
      operation begins in response to a signal from ASP.NET, the page returns the used thread
      to the thread pool. When this operation completes, this mechanism asks for another
      thread from the thread pool and finishes processing the request. This mechanism helps
      us to manage more efficiently the threads manipulation from the thread pool,
      because threads that were stucked earlier, now can be used for other porpuses.
   </p>
        <p>
      Lets see some code:
   </p>
        <p>
      Firstable, you need to set the Async property on the top on the asp.net page in order
      to use this thing:
   </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&lt;%@Page
      Language=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"C#"</span> Async=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"true"</span> ...
      %&gt;</span>
        </p>
        <p>
      This property set to true, says the page to implement the <strong>IHttpAsyncHandler</strong>.
      Regarding this, you need to register the Begin method and End method of to the <strong>Page.AddOnPreRenderCompleteAsync.</strong></p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
      Register async methods</span>
            <br />
      AddOnPreRenderCompleteAsync(<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   new</span> BeginEventHandler(BeginAsyncOperation),<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   new</span> EndEventHandler(EndAsyncOperation)<br />
      );<br /></span>
        </p>
        <p>
      By these actions, the starts its normal life cycle, until the end of the OnPreRender
      event invocation. At this point the ASP.NET calls the Begin method that we registered
      earlier and the operation begins (calling the database etc...), meanwhile, the thread
      that has been assigned to the request goeas back to the thread pool. At the end of
      the Begin method, an IAsyncResult is being sent automatically to the ASP.NET and let
      it determine in the operation had completed, a new thread is being called from the
      thread pool and there is call to the End method (that we registered earlier, remmember?). 
   </p>
        <p>
          <strong>Note:</strong> We do <u>not</u> need to implement the IAsyncResult interface,
      the Framework implements it for us.
   </p>
        <p>
      The Begin and End Methods:
   </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">IAsyncResult
      BeginAsyncOperation (<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span> sender,
      EventArgs e, AsyncCallback cb, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span> state)<br />
      {<br /><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   //
      Do your things...</span><br /><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   //
      Call the DB and run the long long query...</span><br />
      }<br /></span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> EndAsyncOperation(IAsyncResult
      ar)<br />
      {<br /><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   //
      Do your things...</span><br /><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   //
      Get a response from the DB that the operation is DONE...</span><br />
      }<br /></span>
        </p>
        <p>
      Nide ahhhu? So use it wisely...
   </p>
        <img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=11f0552d-7bfc-4f1c-9154-f5c391e4b9ee" />
      </body>
      <title>Asynchronous Pages in ASP.NET 2.0 - Examination and Walkthrough</title>
      <guid>http://www.eranachum.com/PermaLink,guid,11f0552d-7bfc-4f1c-9154-f5c391e4b9ee.aspx</guid>
      <link>http://www.eranachum.com/PermaLink,guid,11f0552d-7bfc-4f1c-9154-f5c391e4b9ee.aspx</link>
      <pubDate>Sun, 01 Jul 2007 09:26:35 GMT</pubDate>
      <description>&lt;p&gt;
   I had a performance problem in my current working on web application; In one of my
   flows in this application, I had needed to call the database and to update some large
   amount of data over there, but this action had taken lots of time and the outcome
   was that users had to wait a long time until this action will be done, admit it, it
   is frustrating...
&lt;/p&gt;
&lt;p&gt;
   My first kind of solution to this problem was to create a new thred from the IIS's
   thread pool and to&amp;nbsp;assign this action under it - quite good resolution not? BUT,
   I reminded that asp.net 2.0 (also 1.X) already implements it in a better and friendly
   way, using &lt;strong&gt;Asynchronous Pages&lt;/strong&gt;.
&lt;/p&gt;
&lt;p&gt;
   &lt;em&gt;But first, some Background...&lt;br&gt;
   &lt;/em&gt;As we all know (or not), when ASP.NET receives a request from the user, it&amp;nbsp;ask
   for&amp;nbsp;a thread from a thread pool and assigns that request to the thread. In order
   to this action, the synchronous page holds this thread for the duration of the request,
   and preventing it from being used by other requests. That leads us to my problem:
   when I am calling to the database and doing the long long action (an UPDATE query),
   the thread assigned to the request is &lt;strong&gt;stuck&lt;/strong&gt; doing nothing until the
   call returns. (This happens because the thread pool has a finite number of threads
   available). 
&lt;/p&gt;
&lt;p&gt;
   &lt;em&gt;The Resolution is (of course) &lt;/em&gt;&lt;strong&gt;Asynchronous Pages.&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
   Asynchronous pages offers a neat solution to such kind of problems. Once&amp;nbsp;an asynchronous
   operation begins in response to a signal from ASP.NET, the page returns the used thread
   to the thread pool. When this operation completes, this mechanism asks for another
   thread from the thread pool and finishes processing the request. This mechanism helps
   us to manage&amp;nbsp;more efficiently the threads manipulation from the thread pool,
   because threads that were stucked earlier, now can be used for other porpuses.
&lt;/p&gt;
&lt;p&gt;
   Lets see some code:
&lt;/p&gt;
&lt;p&gt;
   Firstable, you need to set the Async property on the top on the asp.net page in order
   to use this thing:
&lt;/p&gt;
&lt;p&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;lt;%@Page
   Language=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"C#"&lt;/span&gt; Async=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"true"&lt;/span&gt; ...
   %&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
   This property set to true, says the page to implement the &lt;strong&gt;IHttpAsyncHandler&lt;/strong&gt;.
   Regarding this, you need to register the Begin method and End method of to the &lt;strong&gt;Page.AddOnPreRenderCompleteAsync.&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
   Register async methods&lt;/span&gt;
   &lt;br&gt;
   AddOnPreRenderCompleteAsync(&lt;br&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;new&lt;/span&gt; BeginEventHandler(BeginAsyncOperation),&lt;br&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;new&lt;/span&gt; EndEventHandler(EndAsyncOperation)&lt;br&gt;
   );&lt;br&gt;
   &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
   By these actions, the starts its normal life cycle, until the end of the OnPreRender
   event invocation. At this point the ASP.NET calls the Begin method that we registered
   earlier and the operation begins (calling the database etc...), meanwhile, the thread
   that has been assigned to the request goeas back to the thread pool. At the end of
   the Begin method, an IAsyncResult is being sent automatically to the ASP.NET and let
   it determine in the operation had completed, a new thread is being called from the
   thread pool and there is call to the End method (that we registered earlier, remmember?). 
&lt;/p&gt;
&lt;p&gt;
   &lt;strong&gt;Note:&lt;/strong&gt; We do &lt;u&gt;not&lt;/u&gt; need to implement the IAsyncResult interface,
   the Framework implements it for us.
&lt;/p&gt;
&lt;p&gt;
   The Begin and End Methods:
&lt;/p&gt;
&lt;p&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;IAsyncResult
   BeginAsyncOperation (&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;object&lt;/span&gt; sender,
   EventArgs e,&amp;nbsp;AsyncCallback cb, &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;object&lt;/span&gt; state)&lt;br&gt;
   {&lt;br&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;//
   Do your things...&lt;/span&gt;
   &lt;br&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;//
   Call the DB and run the long long query...&lt;/span&gt;
   &lt;br&gt;
   }&lt;br&gt;
   &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; EndAsyncOperation(IAsyncResult
   ar)&lt;br&gt;
   {&lt;br&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;//
   Do your things...&lt;/span&gt;
   &lt;br&gt;
   &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;//
   Get a response from the DB that the operation is DONE...&lt;/span&gt;
   &lt;br&gt;
   }&lt;br&gt;
   &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
   Nide ahhhu? So use it wisely...
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=11f0552d-7bfc-4f1c-9154-f5c391e4b9ee" /&gt;</description>
      <category>.NET 2005;ASP.NET;Multi-threading</category>
    </item>
    <item>
      <trackback:ping>http://www.eranachum.com/Trackback.aspx?guid=03c7b352-1876-4c0a-b03f-9397e3faa35b</trackback:ping>
      <pingback:server>http://www.eranachum.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.eranachum.com/PermaLink,guid,03c7b352-1876-4c0a-b03f-9397e3faa35b.aspx</pingback:target>
      <dc:creator>eranachum@hotmail.com (Eran Nachum)</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
      I had a debate (friendly one of course...) with a co-worker of mine, called Maayan.
      We discussed about what is the best place to save quite large of data that need to
      be used frequently in my web application, should we store it in the <em>Application</em> object
      or the prefered way - store it in the <em>Cache</em> object?
   </p>
        <p>
      Before we'll go to the conclution, lets get some details about these 2 terms and the
      vast term called <strong>Caching</strong> in applications.
   </p>
        <p>
      2nd before - I am not going to invent the wheel on this post, just to sharpen
      some points that I think that are missing or came up for most of us...
   </p>
        <p>
      Caching is the most effective technique you can use to improve the performance of
      your ASP.NET web application. Designing your application with caching in mind, improves
      both the performance and the scalability of that application. Caching is about storing
      data in memory the first time it is requested and then re-using it for the following
      requests for a specified period of time.
   </p>
        <p>
      ASP.NET provides very convenient API in order to use this term for the best and easy
      way, reffered also to Application data object and Output Cache of course.
   </p>
        <p>
      You can cache the application data using the <strong>System.Web.Caching.Cache</strong> class.
      One instance of this class is created per application domain, and it remains valid
      as long as the application domain remains active. This object is global which means
      its data is avaiable anywhere at the application scope.
   </p>
        <p>
      Now, to the big question: What is more recomended for storing the data, Cache object
      or Application object?
   </p>
        <p>
      Well, the main difference between them is that he cache object has some more powerful
      features that allows you to control the cached data. Which this object, each of the
      data item has its priority state and expiration time. This object has 2 important
      issues handling: When your system's memory becomes short, the chache object knows
      to remove data items with low priorety and free its memory, by that the cahce ensures
      that unnecessary items does not consume valuable server resources.
   </p>
        <p>
      One more good adventage (in ASP.NET of course) is to cache the pages' data. ASP.NET
      allows you to cache web pages or portions of them, calling this an output caching.
      By caching frequently requested pages or portions of them, you can substantially increases
      your web server throughput and get a fast page response. You can cache pages on devices
      like: the web browser making the request, the web server responding to the request,
      and any other cache capable devices such as proxy servers. To read some more information
      about it go <a href="http://aspnet.4guysfromrolla.com/articles/121306-1.aspx" target="_blank">here</a>).
   </p>
        <p>
          <strong>Conclution:</strong> I think that for more complex data manipulation caching,
      the recommended way is to use the cache object and API, but if you want to use and
      cache some 'dummy' data (or just data that not has to be modified and managed during
      the application), use the application object (or session object - per user's session)
      to chach your data.
   </p>
        <img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=03c7b352-1876-4c0a-b03f-9397e3faa35b" />
      </body>
      <title>Output Cache or Application object - Some facts and differences</title>
      <guid>http://www.eranachum.com/PermaLink,guid,03c7b352-1876-4c0a-b03f-9397e3faa35b.aspx</guid>
      <link>http://www.eranachum.com/PermaLink,guid,03c7b352-1876-4c0a-b03f-9397e3faa35b.aspx</link>
      <pubDate>Thu, 21 Jun 2007 15:12:40 GMT</pubDate>
      <description>&lt;p&gt;
   I had a debate (friendly one of course...) with a co-worker of mine, called Maayan.
   We discussed about what is the best place to save quite large of data that need to
   be used frequently in my web application, should we store it in the &lt;em&gt;Application&lt;/em&gt; object
   or the prefered way - store it in the &lt;em&gt;Cache&lt;/em&gt; object?
&lt;/p&gt;
&lt;p&gt;
   Before we'll go to the conclution, lets get some details about these 2 terms and the
   vast term called &lt;strong&gt;Caching&lt;/strong&gt; in applications.
&lt;/p&gt;
&lt;p&gt;
   2nd before -&amp;nbsp;I am not going to invent&amp;nbsp;the wheel on this post, just to sharpen
   some points that I think that are missing or came up for most of us...
&lt;/p&gt;
&lt;p&gt;
   Caching is the most effective technique you can use to improve the performance of
   your ASP.NET web application. Designing your application with caching in mind, improves
   both the performance and the scalability of that application. Caching is about storing
   data in memory the first time it is requested and then re-using it for the following
   requests for a specified period of time.
&lt;/p&gt;
&lt;p&gt;
   ASP.NET provides very convenient API in order to use this term for the best and easy
   way, reffered also to Application data object and Output Cache of course.
&lt;/p&gt;
&lt;p&gt;
   You can cache the application data using the &lt;strong&gt;System.Web.Caching.Cache&lt;/strong&gt; class.
   One instance of this class is created per application domain, and it remains valid
   as long as the application domain remains active. This object is global which means
   its data is avaiable anywhere at the application scope.
&lt;/p&gt;
&lt;p&gt;
   Now, to the big question: What is more recomended for storing the data, Cache object
   or Application object?
&lt;/p&gt;
&lt;p&gt;
   Well, the main difference between them is that he cache object has some more powerful
   features that allows you to control the cached data. Which this object, each of the
   data item has its priority state and expiration time. This object has 2 important
   issues handling: When your system's memory becomes short, the chache object knows
   to remove data items with low priorety and free its memory, by that the cahce ensures
   that unnecessary items does not consume valuable server resources.
&lt;/p&gt;
&lt;p&gt;
   One more good adventage (in ASP.NET of course) is to cache the pages' data. ASP.NET
   allows you to cache web pages or portions of them, calling this an output caching.
   By caching frequently requested pages or portions of them, you can substantially increases
   your web server throughput and get a fast page response. You can cache pages on devices
   like: the web browser making the request, the web server responding to the request,
   and any other cache capable devices such as proxy servers. To read some more information
   about it go &lt;a href="http://aspnet.4guysfromrolla.com/articles/121306-1.aspx" target=_blank&gt;here&lt;/a&gt;).
&lt;/p&gt;
&lt;p&gt;
   &lt;strong&gt;Conclution:&lt;/strong&gt; I think that for more complex data manipulation caching,
   the recommended way is to use the cache object and API, but if you want to use and
   cache some 'dummy' data (or just data that not has to be modified and managed during
   the application), use the application object (or session object - per user's session)
   to chach your data.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.eranachum.com/aggbug.ashx?id=03c7b352-1876-4c0a-b03f-9397e3faa35b" /&gt;</description>
      <category>ASP.NET</category>
    </item>
  </channel>
</rss>