public static string GetLanguage(
            MvcRequest request,
            string site)
        {
            //HttpRequest request = HttpContext.Current.Request;
            string lang = null;

            //  try to get language setting from cookie
            try {
                if (request.GetCookie(MVC_COOKIE_COLLECTION) != null) {
                    lang = request.GetCookie(MVC_COOKIE_COLLECTION)[LANGUAGE_COOKIE];
                }

                //  try to get language setting from request's UserLanguages
            // ?? do we want to use this method??
            //			if (lang == null) {
            //				string userLang = request.UserLanguages[0];
            //				if (userLang[2] == '-') {
            //					lang = userLang.Substring(0, 2);
            //				} else {
            //				}
            //			}
            } catch {
                int k = 0;
            }

            if (lang == null) {
                XmlConfiguration siteConfig = SitesConfig.GetInstance().GetConfig("sites", site.ToUpper());
                if (siteConfig != null) {
                    lang = siteConfig.GetValue("//defaultLanguage");
                }
            }

            // TODO: determine how to put language back in as a cookie
            //request.[MVC_COOKIE_COLLECTION][LANGUAGE_COOKIE] = lang;

            return lang;
        }
        private IState GetStartState(
            MvcRequest request)
        {
            long? curStateId = null;
            bool useStateParam = false;

                //  get the setting from the config for whether or not to get the state
                //  ID from the "st" parameter
            try {
            if (ConfigurationManager.AppSettings["useStateParam"] != null) {
                useStateParam = bool.Parse(ConfigurationManager.AppSettings["useStateParam"]);
            }
            } catch {}

                //  try getting the state from the request, if needed
            if (useStateParam) {
            try {
                curStateId = long.Parse(request[STATE_PARAM_NAME]);
            } catch {}
            }

                //  if we don't have a start state yet, try getting it from session
            if (!curStateId.HasValue) {
            try {
                // TODO: this should NOT reference HttpContext!
                curStateId = long.Parse((string)SessionStateProvider.GetSessionState()[CUR_STATE_NAME]);
            } catch {}
            }

                //  if we still don't have a start state, try getting it from the cookie
            if (!curStateId.HasValue) {
            try {
                curStateId = long.Parse(request.GetCookie(CUR_STATE_NAME).Value);
            } catch {}
            }

                //  as a last resort, try the parameter if we didn't already
            if ((!curStateId.HasValue) && !useStateParam) {
            try {
                curStateId = long.Parse(request[STATE_PARAM_NAME]);
            } catch {}
            }

            if (!curStateId.HasValue) {
            LogManager.GetCurrentClassLogger().Error(
                errorMessage => errorMessage("DoTransitionCommand: State or Event missing."));
            throw new ApplicationException("Start State is missing.");
            }

            IState startState = StateManager.GetInstance().GetState(curStateId.Value);

            if (!(startState is StartState)) {
            throw new ApplicationException("State is not a StartState: startState= " + startState.Id);
            }

            return startState;
        }