代码之家  ›  专栏  ›  技术社区  ›  Gopi

ASP.NET AJAX+HTTP模块失败

  •  0
  • Gopi  · 技术社区  · 16 年前

    我正在尝试使用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中删除时间模块时,我的Ajax工作正常。如果添加时间模块,则标签不会显示消息“登录成功”。

    移除Ajax面板,在httpmodule可用的情况下,标签会显示消息。那么,Ajax面板如何与httpmodules相关?

    2 回复  |  直到 16 年前
        1
  •  0
  •   Timores    16 年前

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

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

        2
  •  0
  •   lasseeskildsen    16 年前

    如果您在登录方法中设置了一个断点,那么它是否命中了该断点?

    推荐文章