asp.net ajax + http模块失败

发布于 2024-08-29 05:28:32 字数 1929 浏览 4 评论 0原文

我正在尝试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 panel 与 httpmodules 是如何关联的呢?

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

栀子花开つ 2024-09-05 05:28:33

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

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

醉酒的小男人 2024-09-05 05:28:32

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文