RealProxy AOP过滤方法的参数
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Runtime.Remoting.Proxies;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Remoting.Activation;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Services;
namespace TestRealProxy
{ public class SqlVerifyProxy : RealProxy
{
MarshalByRefObject _target = null;
public SqlVerifyProxy(Type type, MarshalByRefObject target)
: base(type)
{
this._target = target;
}
//覆写Invoke,处理RealProxy截获的各种消息,
//此种方式最简捷,但不能截获远程对象的激活,好在我们并不是真的要Remoting
public override IMessage Invoke(IMessage msg)
{
IMethodCallMessage call = (IMethodCallMessage)msg;
IConstructionCallMessage ctr = call as IConstructionCallMessage;
IMethodReturnMessage back = null;
//构造函数,只有ContextBoundObject(Inherit from MarshalByRefObject)对象才能截获构造函数
if (ctr != null)
{
RealProxy defaultProxy = RemotingServices.GetRealProxy(_target);
//如果不做下面这一步,_target还是一个没有直正实例化被代理对象的透明代理,
//这样的话,会导致没有直正构建对象。
defaultProxy.InitializeServerObject(ctr);
//本类是一个RealProxy,它可通过GetTransparentProxy函数得到透明代理
back = EnterpriseServicesHelper.CreateConstructionReturnMessage(ctr, (MarshalByRefObject)GetTransparentProxy());
}
//MarshalByRefObject对象就可截获普通的调用消息,
//MarshalByRefObject对象告诉编译器,不能将其内部简单的成员函数优化成内联代码,
//这样才能保证函数调用都能截获。
else
{ IDictionary<string, object> dic = new Dictionary<string, object>(); //过滤参数
for (int i = ; i < call.Args.Length;i++ )
{
if (call.Args[i].ToString().Contains(""))
call.Args[i] = call.Args[i].ToString().Replace("", "123--");
}
//dic = actionContext.ActionArguments;
//if (dic != null && dic.Count > 0)
//{
// foreach (var m in dic)
// {
// string o = m.Value;//.ToJson();
// // Utils.Filter(o);
// }
//} System.IO.File.AppendAllText(System.Web.HttpContext.Current.Server.MapPath("~/1.txt"), string.Join(",", call.Args) + "=================");
back = RemotingServices.ExecuteMessage(_target, call);
}
return back;
}
} //从ProxyAttribute继承,自动实现RealProxy植入
[AttributeUsage(AttributeTargets.Class)]
class SqlVerifyProxyAttribute : ProxyAttribute
{
//覆写CreateInstance函数,返回我们自建的代理
public override MarshalByRefObject CreateInstance(Type serverType)
{
MarshalByRefObject obj = base.CreateInstance(serverType);
SqlVerifyProxy proxy = new SqlVerifyProxy(serverType, obj);
return (MarshalByRefObject)proxy.GetTransparentProxy();
}
} /// <summary>
/// 业务代码,需要继承 ContextBoundObject ,凡是调用 Test方法下的方法都会AOP
/// </summary>
[SqlVerifyProxy]
public class Test : ContextBoundObject
{ public void say(string msg)
{ } } }
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TestRealProxy; namespace TestRealProxy2.Controllers
{ [HandleError]
public class HomeController : Controller
{ public ActionResult Index(string id)
{
//只要调用Test了类下的方法,都会过滤参数
Test t = new Test();
t.say(id);
return View();
} public ActionResult About()
{
return View();
}
}
}
RealProxy AOP过滤方法的参数的更多相关文章
- Spring AOP获取方法的参数名称和参数值
aop配置: <aop:aspectj-autoproxy expose-proxy="true" /> @Before(value = "execution ...
- 动态代理AOP实现方法过滤
上一节实现了动态代理,接下来 有时候,我不需要在每一个方法都要记录日志,做权限验证 等等. 所有就有了这样的需求.AOP实现特定方法过滤,有选择性的来对方法实现AOP 拦截.就是本节标题所示. 举个例 ...
- 使用Spring Aop验证方法参数是否合法
先定义两个注解类ValidateGroup 和 ValidateFiled ValidateGroup .java package com.zf.ann; import java.lang.annot ...
- Spring AOP中使用args表达式访问目标方法的参数
Spring AOP 的使用过程理解 首先,aop的使用场景介绍: 1.处理一些通用的非功能性的需求,不影响业务流程,比如说打印日志.性能统计.推送消息等: 2.aop无法拦截static.final ...
- js进阶 11-15 jquery过滤方法有哪些
js进阶 11-15 jquery过滤方法有哪些 一.总结 一句话总结:jquery方法中的参数一般是什么:选择器.元素或 jQuery 对象. 1.jquery方法中的参数一般是什么? 选择器.元 ...
- 2. Bean Validation声明式校验方法的参数、返回值
你必须非常努力,才能干起来毫不费力.本文已被 https://www.yourbatman.cn 收录,里面一并有Spring技术栈.MyBatis.JVM.中间件等小而美的专栏供以免费学习.关注公众 ...
- js--数组的filter()过滤方法的使用
前言 你还在通过for循环遍历数组吗?你还在遍历之后一项一项的通过if判断过滤你需要的数据吗?你还在写着一大堆代码实现一个简单的过滤数据功能吗?那么,今天他来了.他就是这里要介绍的es6中数组filt ...
- Java:方法的参数是传值还是传引用
Java中方法的参数总是采用传值的方式. 下列方法欲实现对象的交换,但实际上是不能实现的. public void swap(simpleClass a,simpleClass b){ simpleC ...
- MVC学习系列2--向Action方法传递参数
首先,新建一个web项目,新建一个Home控制器,默认的代码如下: public class HomeController : Controller { // GET: Home public Act ...
随机推荐
- JSON 中的 key
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.易于人阅读和编写.同时也易于机器解析和生成.它基于JavaScript(Standard ECMA-262 ...
- python 设计模式之中介模式
Mediator Pattern:中介模式 中介模式提供了一系列统一的系统接口.此模式也被认为是行为模式,因为他能选择程序处理流程. 当许多类开始在交互中产生结果时,可以选用中介模式.当软件开始组织 ...
- nginx的location匹配
http://www.cnblogs.com/lidabo/p/4169396.html 这个博主写的非常好 location: 先匹配普通location,再匹配正则表达式 1.而且选择了最大前缀匹 ...
- android intent打开各种文件的方法
android intent打开各种文件的方法 1./** * 检测是否安装了某个软件 * * @param pkgName "com.bill99.kuaishua" ...
- delphi 读取编译的version信息
在create中调用就可以了 unit About; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, ...
- delphi程序全屏显示无标题栏覆盖整个屏幕
delphi 简单实现程序全屏显示无标题栏,覆盖整个屏幕,这个在做工控机或屏保时有用的,具体代码如下,感兴趣的朋友可以参考下哈 delphi 程序全屏显示无标题栏,覆盖整个屏幕,这个在做工控机或屏保时 ...
- 【maven】maven的web项目打包报错:No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK
打包过程中报错如下: No compiler is provided in this environment. Perhaps you are running on a JRE rather than ...
- C#实现在Form上截取消息的两种方法
比较常用的是重载Form的DefWndProc方法,例如截取鼠标按下的消息: protected override void DefWndProc(ref Message m) { if ( m.Ms ...
- ArcGIS Viewer for Flex中引入google map作底图 (转)
在ArcGIS Viewer for Flex开发中,经常需要用到google map作为底图,我们不能通过ArcGIS Viewer for Flex - Application Builder轻易 ...
- ios开发中APP底部上滑不能调出如WiFi、蓝牙、播放等的设置页面的解决的方法
在开发的APP中我们通常通过手动底部上滑来调出WiFi.蓝牙.飞行模式等的设置页面.有时我们开发的APP无法调出. 解决的方法: 进入iPhone "设置" --> &quo ...