asp.net mvc通过预处理实现数据过滤和数据篡改。
2024-09-23 20:55:47
需求特别简单。在 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
大功告成。
就这么快乐的完成了。
最新文章
- 【WCF】为终结点地址应用地址头
- Js添加消息提示数量
- Hadoop基础学习框架
- UDP通讯程序设计
- wordpress自动批量定时发布插件 DX-auto-publish
- Phonegap开发的前后台数据交互
- 你真的理解z-index吗?
- hdu 1113 Word Amalgamation
- ARM体系架构下的同步操作
- 11g RAC R2 日常巡检--Grid
- SQL VIEW(视图)
- 提升ReSharper和Visual Studio的性能
- sqlalchemy--group_concat的使用
- MAC下pyenv和pyenv-virtualenv插件初探
- f12 headers 变字典快捷方式
- javascript浅拷贝深拷贝详解
- JAVA首次课堂测试总结
- Gym 101775B - Scapegoat - [贪心+优先队列]
- 机器学习-Python中训练模型的保存和再使用
- E - Tears of Drowned