UnityHttpModule Bug

Oct 22, 2010 at 11:47 PM

I am using the http module as recomended by Microsoft here http://msdn.microsoft.com/en-us/library/ff664534(PandP.50).aspx . I believe it's identical to Mr. Tavares proof of concept posted http://blogs.msdn.com/b/mpuleio/archive/2008/07/17/proof-of-concept-a-simple-di-solution-for-asp-net-webforms.aspx.  The http module seems to cause issues with viewstate restore. This example

can be reproduced with Visual studio 2008, and the HttpModule identified in the above link or the one in Mr. Tavares proof of concept.

-- form1
<form id="form1" runat="server">
<asp:GridView ID="myGrid" runat="server" />
<asp:Label ID="mylabel" runat="server" />
<asp:Button ID="btnToggle" runat="server" onclick="btnToggle_Click" Text="DoPostBack" />   
</form>

-- form1 code behind
protected void Page_Load(object sender, EventArgs e)
{
 if (!Page.IsPostBack)
        {
                List<string> emps = new List<string>();
                emps.Add("serge");
                emps.Add("sim");
                myGrid.DataSource = emps;
                myGrid.DataBind();
        }
       
}
       
protected void btnToggle_Click(object sender, EventArgs e)
{
 mylabel.Text = "Is the list still there after post back?";
}

If you have the http module registered in the web.config the example will post back and the list will disappear. If you remove the http module and try the example again
the list is preserved on postback !!! This is the normal Asp.net behaviour.  The same happens with datagrid, dataview and all
the telerick rad grid controls. Since this is the Microsoft recommended approach
maybe someone could shed some light on what might be the problem. I would hate to go back to the base page approach of injecting dependencies. The http module does inject dependencies in pages just fine it just seems to mess up normal processing behaviour that is crucial to our application.

 

 

Mar 18, 2011 at 6:39 PM
Edited Mar 18, 2011 at 6:55 PM

Found a solution here http://stackoverflow.com/questions/4852396/asp-net-4-0-gridview-onrowediting-events-not-firing-when-using-unity-2-0-http-mod

Mar 19, 2011 at 5:25 PM

yes that seems to work. It amazes me that it took 5 months for someone to reply to what is obviously a pretty nasty bug with what MS recomended. I ended up having to ditch the http module

in favor of pulling references from a boostrapped unity container (something akin to the common service locator for unity). Nevertheless, for those who have not spent the same amount of time

on this bug as I did you can also try this  version of the http module http://unity.codeplex.com/Thread/View.aspx?ThreadId=57051. It does pretty much the same thing as what you posted above, it some event handling to the "PreLoad".