如何 在 继承IhttpModule的 过滤关键字的方法里 在请求页面里弹框
请问这个功能可以实现吗 如何实现? public void Init(HttpApplication context)
{
context.AcquireRequestState += new EventHandler(context_BeginRequest);
} #endregion
void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
HttpContext context = application.Context;
Page current = HttpContext.Current.CurrentHandler as Page;
string key = "";
if (context.Request.Form != null)
{
for (int i = 0; i < context.Request.Form.Count; i++)
{
key = context.Request.Form[i];
if (!FilterText(key))
{
//MessageBox.Show(current, "输入内容包含非法字符");
//return;
在此弹框 }
}
}
}
请问这个功能可以实现吗 如何实现? public void Init(HttpApplication context)
{
context.AcquireRequestState += new EventHandler(context_BeginRequest);
} #endregion
void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
HttpContext context = application.Context;
Page current = HttpContext.Current.CurrentHandler as Page;
string key = "";
if (context.Request.Form != null)
{
for (int i = 0; i < context.Request.Form.Count; i++)
{
key = context.Request.Form[i];
if (!FilterText(key))
{
//MessageBox.Show(current, "输入内容包含非法字符");
//return;
在此弹框 }
}
}
}
等待 高手
current.ClientScript.RegisterClientScriptBlock(current.GetType(), "error", "alert('输入内容包含非法字符');", true);
or
current.Response.Write("<script>alert('输入内容包含非法字符');</script>");
current.Response.End();
current.Response.Write("<script>alert('输入内容包含非法字符');location.href='error.aspx';</script>");
current.Response.End();
但我试了你的方法 第一个有和没有都一样 依旧提示错误
下面两个方法提示错误 “响应在此上下文中不可用。”
context.Response.Clear();
context.Response.Write("<script>alert('输入内容包含非法字符');location.href='error.aspx';</script>");
context.Response.End();
但Response.Redirect 可以用~ 可不可以是页面 请求结束 直接相应本页面啊
{
HttpApplication app = sender as HttpApplication;
app.CompleteRequest();
app.Context.Response.Write("输入内容包含非法字符");
}
问题解决了
application.CompleteRequest();
application.Context.Response.Write("<script>alert('输入内容包含非法字符');location.href='" + context.Request.FilePath + "'</script>");再次感谢
不过 怎样使 HttpModuole 只对制定页面判断 不要每个页面都判断呢如有志愿者 我另加分
应该把context.Response.End();这句去掉
在 不需要验证的页面时 不会去 调用HttpModule类