1 /* ****************************************************************************
\r
3 * Copyright (c) Microsoft Corporation. All rights reserved.
\r
5 * This software is subject to the Microsoft Public License (Ms-PL).
\r
6 * A copy of the license can be found in the license.htm file included
\r
7 * in this distribution.
\r
9 * You must not remove this notice, or any other, from this software.
\r
11 * ***************************************************************************/
\r
13 namespace System.Web.Mvc {
\r
15 using System.Collections.Generic;
\r
16 using System.Web.Mvc.Resources;
\r
18 public class SessionStateTempDataProvider : ITempDataProvider {
\r
19 internal const string TempDataSessionStateKey = "__ControllerTempData";
\r
21 public virtual IDictionary<string, object> LoadTempData(ControllerContext controllerContext) {
\r
22 HttpContextBase httpContext = controllerContext.HttpContext;
\r
24 if (httpContext.Session == null) {
\r
25 throw new InvalidOperationException(MvcResources.SessionStateTempDataProvider_SessionStateDisabled);
\r
28 Dictionary<string, object> tempDataDictionary = httpContext.Session[TempDataSessionStateKey] as Dictionary<string, object>;
\r
30 if (tempDataDictionary != null) {
\r
31 // If we got it from Session, remove it so that no other request gets it
\r
32 httpContext.Session.Remove(TempDataSessionStateKey);
\r
33 return tempDataDictionary;
\r
36 return new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
\r
40 public virtual void SaveTempData(ControllerContext controllerContext, IDictionary<string, object> values) {
\r
41 HttpContextBase httpContext = controllerContext.HttpContext;
\r
43 if (httpContext.Session == null) {
\r
44 throw new InvalidOperationException(MvcResources.SessionStateTempDataProvider_SessionStateDisabled);
\r
47 httpContext.Session[TempDataSessionStateKey] = values;
\r