我正在构建用户调用的操作历史记录。为此,我需要原始查询字符串中的所有参数。这需要在OnActionExecuted(动作之后)完成,因为一些描述信息存储在filterAction.Result.Model.MyDescription中。
在ActionExecutedContext上,我无权访问ActionParameters,而RoutesValues只包含action,controller,id和culture。它不包含查询字符串中包含的任何其他参数。
如何将OnActionExecuting的ActionParameters保存到OnActionExecuted?
控制器:
[ReportHistoryLink]
public ActionResult Index(int id, DateTime at, string by)
{
var model = new ReportModel();
model.ReportDescription = "Some logic get the ReportDescription";
return View("Index", model);
}
ActionFilter:
public class ReportHistoryLinkAttribute : ActionFilterAttribute
{
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
var model = (IModelWithReportDescription)((ViewResult)filterContext.Result).Model;
var description = model.ReportDescription;
var boxedId = filterContext.RouteData.Values["id"];
var id = Convert.ToInt32(boxedId);
if (id != 0 && !string.IsNullOrWhiteSpace(targetDescription))
{
var link = new HistoryLink
{
Id = id,
Description = description,
Route = filterContext.RouteData.Values //This doesn't contains the "at and by parameters"
};
}
}
}
答案 0 :(得分:3)
您可以使用
filterContext.HttpContext.Request.QueryString["id"]