views:

112

answers:

2

Hi,

I am trying my hands on asp.net+ajax+httpmodule.

My Form

<form id="LoginForm" runat="server">
<asp:ScriptManager ID="LoginScriptMgr" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="LoginPanel" runat="server">
    <ContentTemplate>
        <asp:Label ID="lblLoginHeader" Text="Login" runat="server"></asp:Label>
        <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
        <asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox>
        <asp:Button ID="btnLogin" Text="Login" runat="server" OnClick="Login" />
        <asp:Label ID="lblLoginStatus" runat="server" />
    </ContentTemplate>
</asp:UpdatePanel>
</form>

C# Code

protected void Login(object sender, EventArgs e)
{
lblLoginStatus.Text = "Login Successful";
}

Web.config

<httpModules>
  <add name="TimeModule" type="MyWebPortal.App_Code.TimeModule,App_Code"/>
</httpModules>

HTTP Module

public class TimeModule : IHttpModule
{
    private HttpApplication oApps = null;
    public void Dispose()
    {
    }
    public void Init(System.Web.HttpApplication context)
    {
        oApps = context;
        context.PreSendRequestContent += new EventHandler
        (context_PreSendRequestContent);
    }
    void context_PreSendRequestContent(object sender, EventArgs e) 
    {
        string message = "&lt;!-- This page is being processed at " + System.DateTime.Now.ToString() + " -->";
        oApps.Context.Response.Output.Write(message);
    }
}

When i remove the TimeModule from Web.config my ajax works. If add the TimeModule then the label doesn't show the message "Login Successful".

Removing the ajax panel and with httpmodule available the label shows the message. So, how ajax panel was related to httpmodules?

A: 

If you set a breakpoint in the Login method, does it hit the breakpoint then?

lasseeskildsen
Yeah. It hits the break point but the update process never happens if i add TimeModule
Sri Kumar
I think that writing the html comment to the response might mess it up causing the error. Have you tried to keep the module there, but comment out the lines where you add to the output?
lasseeskildsen
A: 

I think that the problem is that what you are sending in the module interferes with the normal response stream. This stream is structured, i.e. has a header and body.

Try adding the comment with the PostRequestHandlerExecute. The result should not be 100% correct, but it should not interfere.

Timores
Changed the line: context.PostRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecuteContent); still now o/p
Sri Kumar