【发布时间】: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 = "<!-- 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