public class CustomerAttribute : ActionFilterAttribute { public string Message { get; set; } public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext) { Message = actionContext.ControllerContext.GetType().Name + " 's " + actionContext.ActionDescriptor.ActionName; base.OnActionExecuting(actionContext); } public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) { base.OnActionExecuted(actionExecutedContext); } }
在
OnActionExecuting 或
OnActionExecuted方法里怎么输出一段文本呢,
在MVC3有
filterContext.HttpContext.Response.Write(string.Format("<br/> {0} Action finish Execute.....", Message));
但在MVC4里这个方法参数变了。
1 public override void OnActionExecuted(HttpActionExecutedContext context) 2 { 3 var content = "hello"; 4 5 context.Response.Content = new StringContent(content); 6 }