从Global.asax设置tempdata

时间:2011-05-04 09:43:48

标签: asp.net-mvc-2

如何从Global.asax中设置 tempdata?

asp.net-mvc-2

1 个答案:

答案 0 :(得分:4)

Dictionary<string, object> tempDataDictionary = Context.Session["__ControllerTempData"] as Dictionary<string, object>;
                if (tempDataDictionary == null)
                {
                    tempDataDictionary = new Dictionary<string, object>();
                }
                **tempDataDictionary["TopMessage"] = message;
                tempDataDictionary["FromUnauthorized"] = true;
                HttpContext.Current.Session["__ControllerTempData"] = tempDataDictionary;**
                Server.ClearError();
                Response.Redirect("~/Account/LogOn");