重定向到行动没有携带异常数据 [英] Redirect To Action not carrying exception data

查看:138
本文介绍了重定向到行动没有携带异常数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本的控制器所花excption小心处理。因此,在控制器的所有我的行为只是委托给在basecontroller的动作。

I have a base controller which takes care of excption handling . so all my actions in the controller simply delegate to the action in basecontroller.

 catch (Exception ex)
            {
                return RedirectToAction("Error", ex);
            }

我的基本控制器动作

my base controller action is

   public ActionResult Error(Exception ex)

这里

德问题是错误时抛出的细节是错误的行动得到海关收缴的基本控制器。我想重定向在这些越来越被清除。

Teh problem here is excpetion details are getting clreared in Error Action in base controller. I think these are getting cleared during redirection.

推荐答案

是的,这是正确的,当你做一个重定向你基本上发送302到浏览器,以便将数据丢失。

Yes, that's correct, when you do a redirect you're basically sending a 302 to the browser so the data is lost.

一个可能的方式临时保存的数据保存在TempData的:

A possible way to temporarily save the data is saving it in the tempdata:

TempData["error"] = ex;

之后,你可以在错误的方法检索它:

After that you can retrieve it in the Error-method:

Exception ex = TempData["error"] as Exception;

注:TempData的是短命的数据,可以在重定向消息的情况是特别方便

Note: the tempdata is for short-lived data and can be especially handy in redirect-scenarios

这篇关于重定向到行动没有携带异常数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆