asp.net ajax + http模块失败
我正在尝试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 = "<!-- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果在Login方法中设置断点,那么它会到达断点吗?
If you set a breakpoint in the Login method, does it hit the breakpoint then?
我认为问题在于您在模块中发送的内容会干扰正常的响应流。该流是结构化的,即具有标头和主体。
尝试使用 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.