Filter Attribute:
using My.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Web;
using System.Web.Http.Controllers;
using System.Web.Http.Filters;
namespace My.ActionFilter
{
public class MyAttr : ActionFilterAttribute
{
public override void OnActionExecuting(HttpActionContext actionContext)
{
if (actionContext.ActionArguments.ContainsKey("input") && actionContext.ActionArguments["input"] != null)
{
Parm wx= (Parm)actionContext.ActionArguments["input"];
wx.OpenId = DecodeOpenId.DecryptOpenId(wx.OpenId);
}
if (actionContext.ActionArguments.ContainsKey("OpenId") && !String.IsNullOrEmpty(actionContext.ActionArguments["OpenId"].ToString()))
{
actionContext.ActionArguments["OpenId"] = DecodeOpenId.DecryptOpenId(actionContext.ActionArguments["OpenId"].ToString());
}
}
}
}
使用方法:
namespace My.Areas.MemberManage.Controllers
{
[RoutePrefix("my/api/moduleName")]
[Route("{action}")]
[MyAttr]
public class MyController : ApiController
{
[HttpGet]
[HttpPost]
public void FunctionName(ClassName input)
{
}
}
}