【问题标题】:asp.net ajax + http module failsasp.net ajax + http 模块失败
【发布时间】:2010-04-19 08:01:00
【问题描述】:

我正在尝试使用 asp.net+ajax+httpmodule。

我的表单

<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 中删除 TimeModule 时,我的 ajax 工作。如果添加 TimeModule,则标签不会显示“登录成功”消息。

移除 ajax 面板并使用可用的 httpmodule 标签显示消息。那么,ajax 面板是如何与 httpmodules 相关联的呢?

【问题讨论】:

    标签: c# asp.net asp.net-ajax httpmodule


    【解决方案1】:

    我认为问题在于您在模块中发送的内容会干扰正常的响应流。此流是结构化的,即具有标题和正文。

    尝试使用 PostRequestHandlerExecute 添加评论。结果不应 100% 正确,但不应干扰。

    【讨论】:

    • 更改了行:context.PostRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecuteContent);现在还在o/p
    【解决方案2】:

    如果在Login方法中设置了断点,那么它会碰到断点吗?

    【讨论】:

    • 是的。它达到了断点,但如果我添加 TimeModule,更新过程永远不会发生
    • 我认为将 html 注释写入响应可能会导致错误。您是否尝试将模块保留在那里,但将您添加到输出中的行注释掉?
    猜你喜欢
    • 1970-01-01
    • 2018-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-21
    • 1970-01-01
    • 2017-04-23
    相关资源
    最近更新 更多