我正在开发一个完整的Web应用程序,我正在使用ASP.NET MVC 3框架.我正在实现ActionFilterAttribute的子类.
我正在重写OnActionExecuting方法.如果在OnActionExecuting方法中捕获到异常,我想重定向客户端浏览器.重定向URL以我的一个控制器中的操作方法为目标.我想将Exception对象中的数据传递到重定向URL.
有没有办法构建包含Exception对象的URL,然后将URL传递给RedirectResult构造函数?
解决方法
Is there a way to build a URL including the Exception object and then
passing the URL into the RedirectResult constructor ?
不可以.您只能传递查询字符串参数,例如:
var values = new RouteValueDictionary(new { action = "foo",controller = "bar",exceptiontext = "foo bar baz" }); filterContext.Result = new RedirectToRouteResult(values);
在目标操作中,您将能够获取异常文本参数:
public Action Foo(string exceptionText) { ... }