2010-04-19 72 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