需求特别简单。在 Controller加过滤器。实现在所有的方法上增加id=12312321312.另外将price篡改为price+5。

这样做可以最大的减少代码的改动量,人员变动厉害,业务也模糊了,篡改数据,过滤最简单。

直接上代码

新建Filter.cs

代码如下

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Http.Controllers;
using System.Web.Mvc; namespace MvcApplication3
{ [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class IDAndPriceFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
base.OnActionExecuting(filterContext); var parameters = filterContext.ActionParameters;
if (parameters.Keys.Contains("price"))
{
var price = Convert.ToInt32(parameters["price"]);
price += ; parameters["price"] = price; } parameters["id"] = ;
}
}
}

新建controller

    [IDAndPriceFilter]
public class HomeController : Controller
{
public ActionResult Index(string stuName, int price,int id)
{
return View();
} }

我们在浏览器地址栏里输入如下地址

http://localhost:57159/Home?stuName=maliang&price=100

下载源代码

大功告成。

就这么快乐的完成了。

最新文章

  1. 【WCF】为终结点地址应用地址头
  2. Js添加消息提示数量
  3. Hadoop基础学习框架
  4. UDP通讯程序设计
  5. wordpress自动批量定时发布插件 DX-auto-publish
  6. Phonegap开发的前后台数据交互
  7. 你真的理解z-index吗?
  8. hdu 1113 Word Amalgamation
  9. ARM体系架构下的同步操作
  10. 11g RAC R2 日常巡检--Grid
  11. SQL VIEW(视图)
  12. 提升ReSharper和Visual Studio的性能
  13. sqlalchemy--group_concat的使用
  14. MAC下pyenv和pyenv-virtualenv插件初探
  15. f12 headers 变字典快捷方式
  16. javascript浅拷贝深拷贝详解
  17. JAVA首次课堂测试总结
  18. Gym 101775B - Scapegoat - [贪心+优先队列]
  19. 机器学习-Python中训练模型的保存和再使用
  20. E - Tears of Drowned

热门文章

  1. Oracle 10g -- 修改DB的编码
  2. js 运算符优先级
  3. 统计学习方法笔记 Logistic regression
  4. C#事务的使用
  5. java读取属性文件propertie中文乱码问题
  6. MyEclipse取消验证Js的两种途径.
  7. Java入门1day
  8. Mysql --分区(4)List分区
  9. 斯坦福第十八课:应用实例:图片文字识别(Application Example: Photo OCR)
  10. Excel VBA自动添加证书(二)