写过滤方法 [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)] public class Cookieless : ActionFilterAttribute, IActionFilter { private TextWriter _originalWriter; private static MethodInfo _switchWriterMethod = typeof(HttpResponse).GetMethod("SwitchWriter", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); public override void OnActionExecuting(ActionExecutingContext filterContext) { var request = filterContext.HttpContext.Request; var response = filterContext.HttpContext.Response; _originalWriter = (TextWriter)_switchWriterMethod.Invoke(HttpContext.Current.Response, new object[] { new HtmlTextWriter(new StringWriter()) }); base.OnActionExecuting(filterContext); } public override void OnResultExecuted(ResultExecutedContext filterContext) { var response = filterContext.HttpContext.Response; var request = filterContext.HttpContext.Request; HtmlTextWriter cacheWriter = (HtmlTextWriter)_switchWriterMethod.Invoke(HttpContext.Current.Response, new object[] { _originalWriter }); string textWritten = ((StringWriter)cacheWriter.InnerWriter).ToString(); if (response.ContentType == "text/html") { textWritten = textWritten .Replace(".mvc", ".aspx") .ToString(); } filterContext.HttpContext.Response.Write(textWritten); base.OnResultExecuted(filterContext); } } [Filter.Cookieless] public class ControllerBase : System.Web.Mvc.Controller {}