2010-04-19 123 views
0

我想我的手在asp.net + ajax + httpmodule上。asp.net ajax + http模块失败

我的形式

<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#代码

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模块

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); 
    } 
} 

当我删除从我的Web.config Ajax的工作原理的TimeModule。如果添加TimeModule,则标签不会显示消息“登录成功”。

删除ajax面板和httpmodule可用标签显示消息。那么,ajax面板如何与httpmodules相关?

回答

0

我认为问题在于你在模块中发送的内容会干扰正常的响应流。该流是结构化的,即具有头部和身体。

尝试使用PostRequestHandlerExecute添加注释。结果不应该100%正确,但不应该干涉。

+0

更改了这一行:context.PostRequestHandlerExecute + = new EventHandler(context_PreRequestHandlerExecuteContent);现在仍然是o/p – 2010-04-19 09:16:54

0

如果您在Login方法中设置了断点,它是否会触发断点?

+0

是的。它达到了中断点,但更新过程从未发生,如果我添加TimeModule – 2010-04-19 08:28:48

+0

我认为将html注释写入响应可能会导致错误。您是否试图将模块保留在那里,但注释掉添加到输出中的行吗? – lasseeskildsen 2010-04-20 20:12:10