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过滤方法的参数的更多相关文章

  1. Spring AOP获取方法的参数名称和参数值

    aop配置: <aop:aspectj-autoproxy expose-proxy="true" /> @Before(value = "execution ...

  2. 动态代理AOP实现方法过滤

    上一节实现了动态代理,接下来 有时候,我不需要在每一个方法都要记录日志,做权限验证 等等. 所有就有了这样的需求.AOP实现特定方法过滤,有选择性的来对方法实现AOP 拦截.就是本节标题所示. 举个例 ...

  3. 使用Spring Aop验证方法参数是否合法

    先定义两个注解类ValidateGroup 和 ValidateFiled ValidateGroup .java package com.zf.ann; import java.lang.annot ...

  4. Spring AOP中使用args表达式访问目标方法的参数

    Spring AOP 的使用过程理解 首先,aop的使用场景介绍: 1.处理一些通用的非功能性的需求,不影响业务流程,比如说打印日志.性能统计.推送消息等: 2.aop无法拦截static.final ...

  5. js进阶 11-15 jquery过滤方法有哪些

    js进阶 11-15  jquery过滤方法有哪些 一.总结 一句话总结:jquery方法中的参数一般是什么:选择器.元素或 jQuery 对象. 1.jquery方法中的参数一般是什么? 选择器.元 ...

  6. 2. Bean Validation声明式校验方法的参数、返回值

    你必须非常努力,才能干起来毫不费力.本文已被 https://www.yourbatman.cn 收录,里面一并有Spring技术栈.MyBatis.JVM.中间件等小而美的专栏供以免费学习.关注公众 ...

  7. js--数组的filter()过滤方法的使用

    前言 你还在通过for循环遍历数组吗?你还在遍历之后一项一项的通过if判断过滤你需要的数据吗?你还在写着一大堆代码实现一个简单的过滤数据功能吗?那么,今天他来了.他就是这里要介绍的es6中数组filt ...

  8. Java:方法的参数是传值还是传引用

    Java中方法的参数总是采用传值的方式. 下列方法欲实现对象的交换,但实际上是不能实现的. public void swap(simpleClass a,simpleClass b){ simpleC ...

  9. MVC学习系列2--向Action方法传递参数

    首先,新建一个web项目,新建一个Home控制器,默认的代码如下: public class HomeController : Controller { // GET: Home public Act ...

随机推荐

  1. Codeforces Round #448 (Div. 2) B. XK Segments【二分搜索/排序/查找合法的数在哪些不同区间的区间数目】

    B. XK Segments time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. AppScan入门工作原理详解

    AppScan,即 AppScan standard edition.其安装在 Windows 操作系统上,可以对网站等 Web 应用进行自动化的应用安全扫描和测试. Rational AppScan ...

  3. JQuery里面的知识

    JQuery是一个javaScript库 JQuery极大的简化了javaScript编程 通过点击 "TIY" 按钮来看看它是如何运行的. 演示JQuery的hide函数,隐藏了 ...

  4. socket 和 webservice 的区别和比较

    时间紧迫,我就直奔主题. 目前需要说服客户使用webservice 而不是socket. 我觉得要先分别解释下什么是socket 什么是webservice..这个要我该怎么说才比较形象,让人一定就明 ...

  5. bzoj 2843: 极地旅行社

    Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 1077  Solved: 645[Submit][Status][Discuss] Descripti ...

  6. Bluetooth篇 开发实例之八 匹配

    自己写的App匹配蓝牙设备,不需要通过系统设置去连接. 匹配和通信是两回事. 用过Android系统设置(Setting)的人都知道蓝牙搜索之后可以建立配对和解除配对,但是这两项功能的函数没有在SDK ...

  7. NFS 服务配置篇

    安装.配置NFS服务 1.NFS简介 NFS(network file system) NFS是一个主机A通过网络,允许其他主机B可以来共享主机A的一个目录文件的一个文件系统 2.需要安装两个包nfs ...

  8. 使用nvDXT.exe把图片转换成dds图片【转】

    从nvidia官网下载工具包DDS Utilities [https://developer.nvidia.com/legacy-texture-tools] 转换图片格式需要的工具是 nvdxt.e ...

  9. Linux expect 用法

    expect是建立在tcl基础上的一个工具,它用来让一些需要交互的任务自动化地完成. 因为expect是基于tcl的,所以需要你的系统中安装有tcl 检查是否安装tcl,expect [root@ma ...

  10. 【Docker】Docker管理平台 Rancher ---- 你应该学学Rancher是怎么做容器的管理的

    Elasticsearch is a Lucene-based search engine developed by the open-source vendor, elastic. With pri ...