public void SetContext(ActionExecutingContext controllerContext) { HttpContextBase context = controllerContext.GetHttpContext(); if (context.Session != null) { if (context.Session[TimeZoneContextKey] == null) { var numberOfAttempts = (int)(context.Session[TimeZoneAttemptsKey] ?? 0); string timeZoneIdString = GetTimeZoneIdString(numberOfAttempts, context.Request); TimeZoneInfo timeZone = GetTimeZone(timeZoneIdString); if (timeZone != null) { context.Session[TimeZoneContextKey] = timeZone; context.Session[TimeZoneAttemptsKey] = null; } else { context.Session[TimeZoneAttemptsKey] = ++numberOfAttempts; } } } }