开发者

asp.net ajax + http module fails

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".

开发者_如何学Python

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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜