asp.net webform过滤器(注意我们可以在拦截请求的同时设置回调函数)
.过滤器代码
public class PageFilter : IHttpModule
{
public String ModuleName
{
get { return "PageFilter"; }
} public void Dispose()
{ } //在 Init 方法中注册HttpApplication
// 通过委托方式注册事件
public void Init(HttpApplication application)
{ application.BeginRequest += Application_BeginRequest;
application.Error += Application_Error;
application.AcquireRequestState += new EventHandler(Application_AcquireRequestState);
application.EndRequest += Application_EndRequest;
} private void Application_BeginRequest(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
HttpContext context = application.Context;
HttpSessionState session = context.Session;
HttpRequest request = context.Request;
HttpResponse response = context.Response;
String contextPath = request.ApplicationPath;
var rawUrl = request.RawUrl;
if (rawUrl.Contains("/admin/Sys/SysDictTypeEdit.aspx") && rawUrl.Contains("_method=Save"))
{
System.Diagnostics.Debug.WriteLine("begin request");
} } private void Application_Error(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
HttpContext context = application.Context;
HttpSessionState session = context.Session;
HttpRequest request = context.Request;
HttpResponse response = context.Response;
String contextPath = request.ApplicationPath;
var rawUrl = request.RawUrl;
if (rawUrl.Contains("/admin/Sys/SysDictTypeEdit.aspx") && rawUrl.Contains("_method=Save"))
{
System.Diagnostics.Debug.WriteLine("error");
}
} private void Application_EndRequest(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
HttpContext context = application.Context;
HttpSessionState session = context.Session;
HttpRequest request = context.Request;
HttpResponse response = context.Response;
String contextPath = request.ApplicationPath;
var rawUrl = request.RawUrl;
if (rawUrl.Contains("/admin/Sys/SysDictTypeEdit.aspx") && rawUrl.Contains("_method=Save"))
{
System.Diagnostics.Debug.WriteLine("end request");
}
} private void Application_AcquireRequestState(Object source, EventArgs e)
{
try
{
HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;
HttpSessionState session = context.Session;
HttpRequest request = context.Request;
HttpResponse response = context.Response;
String contextPath = request.ApplicationPath;
if (application.Context.Handler is System.Web.UI.TemplateControl)
{
var path = ((System.Web.UI.TemplateControl)application.Context.Handler).AppRelativeVirtualPath;
if (path == "~/admin/Sys/SysDictTypeEdit.aspx" && request["_method"] == "Save")
{
Action action = () => System.Diagnostics.Debug.WriteLine("Save777");
//注意可以在这里往上下文的IDcitionary里放委托,将来可用于回调(可理解为注册)
context.Items.Add(request["_method"], action);
}
}
}
catch (Exception ex)
{ throw;
}
}
}
.web.config配置
<system.web>
<httpModules>
<add name="pageModule" type="HraWeb.PageFilter,HraWeb"/>
</httpModules>
</system.web>
<system.webserver>
<modules>
<add name="pageModule" type="HraWeb.PageFilter,HraWeb"/>
</modules>
</system.webserver>
asp.net webform过滤器(注意我们可以在拦截请求的同时设置回调函数)的更多相关文章
- ASP.Net WebForm温故知新学习笔记:二、ViewState与UpdatePanel探秘
开篇:经历了上一篇<aspx与服务器控件探秘>后,我们了解了aspx和服务器控件背后的故事.这篇我们开始走进WebForm状态保持的一大法宝—ViewState,对其刨根究底一下.然后,再 ...
- ASP.Net WebForm温故知新学习笔记:一、aspx与服务器控件探秘
开篇:毫无疑问,ASP.Net WebForm是微软推出的一个跨时代的Web开发模式,它将WinForm开发模式的快捷便利的优点移植到了Web开发上,我们只要学会三步:拖控件→设属性→绑事件,便可以行 ...
- ASP.NET MVC 过滤器(一)
ASP.NET MVC 过滤器(一) 前言 前面的篇幅中,了解到了控制器的生成的过程以及在生成的过程中的各种注入点,按照常理来说篇幅应该到了讲解控制器内部的执行过程以及模型绑定.验证这些知识了.但是呢 ...
- ASP.NET MVC 过滤器(三)
ASP.NET MVC 过滤器(三) 前言 本篇讲解行为过滤器的执行过程,过滤器实现.使用方式有AOP的意思,可以通过学习了解过滤器在框架中的执行过程从而获得一些AOP方面的知识(在顺序执行的过程中, ...
- ASP.NET MVC 过滤器(四)
ASP.NET MVC 过滤器(四) 前言 前一篇对IActionFilter方法执行过滤器在框架中的执行过程做了大概的描述,本篇将会对IActionFilter类型的过滤器使用来做一些介绍. ASP ...
- ASP.NET MVC 过滤器(五)
ASP.NET MVC 过滤器(五) 前言 上篇对了行为过滤器的使用做了讲解,如果在控制器行为的执行中遇到了异常怎么办呢?没关系,还好框架给我们提供了异常过滤器,在本篇中将会对异常过滤器的使用做一个大 ...
- asp.net mvc4 过滤器的简单应用:登录验证
直接上代码,不要说话. ASP.NET MVC4过滤器的简单应用:验证登录 [AcceptVerbs(HttpVerbs.Post)] public ActionResult login(FormCo ...
- 一、ASP.NET MVC 路由(一)--- ASP.NET WebForm路由模拟
ASP.NET WebForm 应用,用户请求的是物理文件,其中包括静态页面和动态页面,在Url中的显示都是服务器中一个物理文件的相对路径.但是ASP.NET MVC就不同了,用户请求的是Contro ...
- (转)教你记住ASP.NET WebForm页面的生命周期
对于ASP.NET Webform的开发者,理解ASP.NET Webform的页面生命周期是非常重要的.主要是为了搞明白在哪里放置特定的方法和在何时设置各种页面属性.但是记忆和理解页面生命周期里提供 ...
随机推荐
- 获取响应里面的cookie的方法
使用方法: R.cookies.get_dict() 获取响应返回的cookies
- 写java代码有感。。。构造方法最好带着,
(一) 小结:具体我最大的担心,害怕就是方法调用的时候,new对象之后,赋值,是在new后面的括号里实现,还是在 对象.方法名()这样的.当然带参数的构造方法,调用时本身就直接调用,普通方法,选后者. ...
- vue 跟路径加载缺少跟前缀
vue 加载资源失败:跟路径残缺,都是配置时 一个正斜杠 / 多余惹的祸
- C/C++程序内存情况
一个由C/C++编译的程序占用的内存分为以下几个部分 1.栈区(stack)— 由编译器自动分配释放 ,存放函数的参数值,局部变量的值等.其操作方式类似于数据结构中的栈. 2.堆区(heap) — 一 ...
- 负载均衡的时候如何实现相同的session被分配到同一个服务器
http://www.zhihu.com/question/19651970 session共享那个问题时,有人说:其实从负载均衡的层面来看,大多数硬件/软件的负载均衡方案,都支持session状态保 ...
- MySql For Windows解压缩版配置
#配置步骤 1.首先下载解压. (此处我解压到了我电脑的“E:\software\MySql”这个位置,下文以这个目录举例); 2.我的电脑右键属性,找到环境变量配置,配置环境变量,将mysql.ex ...
- leetcode687
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode ...
- 「小程序JAVA实战」小程序头像图片上传(上)(43)
转自:https://idig8.com/2018/09/08/xiaochengxujavashizhanxiaochengxutouxiangtupianshangchuan40/ 在微信小程序中 ...
- log4j:WARN No appenders could be found for logger 解决办法
转自:https://blog.csdn.net/chw0629/article/details/80567936 使用log4j时不起作用,每次执行完出现以下提示: log4j:WARN No ap ...
- From Ruby array to JS array in Rails- 'quote'?
From Ruby array to JS array in Rails- 'quote'? <%= raw @location_list.as_json %>