Kaynağa Gözat

2004-05-25 Gonzalo Paniagua Javier <[email protected]>

	* System.Web/HttpApplication.cs: set culture/uiculture from
	configuration and restore it after each step. Fixes bug #52851.

	* System.Web.Configuration/GlobalizationConfiguration.cs: if we have no
	context, use GetAppConfig instead of GetConfig.

svn path=/trunk/mcs/; revision=28081
Gonzalo Paniagua Javier 21 yıl önce
ebeveyn
işleme
9634b2bb99

+ 5 - 0
mcs/class/System.Web/System.Web.Configuration/ChangeLog

@@ -1,3 +1,8 @@
+2004-05-25  Gonzalo Paniagua Javier <[email protected]>
+
+	* GlobalizationConfiguration.cs: if we have no context, use
+	GetAppConfig instead of GetConfig.
+
 2004-05-14  Gonzalo Paniagua Javier <[email protected]>
 
 	* CompilationConfiguration.cs: a null value is ok for TempDirectory.

+ 6 - 4
mcs/class/System.Web/System.Web.Configuration/GlobalizationConfiguration.cs

@@ -37,11 +37,13 @@ namespace System.Web.Configuration
 		static public GlobalizationConfiguration GetInstance (HttpContext context)
 		{
 			GlobalizationConfiguration config;
-			if (context == null)
-				context = HttpContext.Context;
-
 			try {
-				config = context.GetConfig ("system.web/globalization") as GlobalizationConfiguration;
+				if (context == null)
+					config = HttpContext.GetAppConfig ("system.web/globalization")
+						 as GlobalizationConfiguration;
+				else
+					config = context.GetConfig ("system.web/globalization")
+						 as GlobalizationConfiguration;
 			} catch {
 				return null;
 			}

+ 5 - 0
mcs/class/System.Web/System.Web/ChangeLog

@@ -1,3 +1,8 @@
+2004-05-25  Gonzalo Paniagua Javier <[email protected]>
+
+	* HttpApplication.cs: set culture/uiculture from configuration and
+	restore it after each step. Fixes bug #52851.
+
 2004-05-18  Gonzalo Paniagua Javier <[email protected]>
 
 	* HttpUtility.cs: use lower case in UrlEncode like MS does. Delay

+ 46 - 5
mcs/class/System.Web/System.Web/HttpApplication.cs

@@ -6,9 +6,13 @@
 // 	Tim Coleman ([email protected])
 // 	Gonzalo Paniagua Javier ([email protected])
 //
+// (c) Copyright 2002-2003 Ximian, Inc. (http://www.ximian.com)
+// (c) Copyright 2004 Novell, Inc. (http://www.novell.com)
+//
 using System;
 using System.Collections;
 using System.ComponentModel;
+using System.Globalization;
 using System.IO;
 using System.Threading;
 using System.Security.Principal;
@@ -733,6 +737,11 @@ namespace System.Web
 		ArrayList _recycleHandlers;
 
 		bool _InPreRequestResponseMode;
+
+		CultureInfo appCulture;
+		CultureInfo appUICulture;
+		CultureInfo prevAppCulture;
+		CultureInfo prevAppUICulture;
 #endregion
 
 #region Constructor
@@ -814,13 +823,46 @@ namespace System.Web
 
 		internal void InitCulture ()
 		{
-			// TODO: Read culture info from globalization from config
+			GlobalizationConfiguration cfg = GlobalizationConfiguration.GetInstance (null);
+			if (cfg != null) {
+				appCulture = cfg.Culture;
+				appUICulture = cfg.UICulture;
+			}
 		}
 
-		internal void OnStateExecuteEnter ()
+		void SaveThreadCulture ()
 		{
-			// TODO: Set correct culture for the thread
+			Thread th = Thread.CurrentThread;
+
+			if (appCulture != null) {
+				prevAppCulture = th.CurrentCulture;
+				th.CurrentCulture = appCulture;
+			}
 
+			if (appUICulture != null) {
+				prevAppUICulture = th.CurrentUICulture;
+				th.CurrentUICulture = appUICulture;
+			}
+		}
+
+		void RestoreThreadCulture ()
+		{
+			Thread th = Thread.CurrentThread;
+
+			if (prevAppCulture != null) {
+				th.CurrentCulture = prevAppCulture;
+				prevAppCulture = null;
+			}
+
+			if (prevAppUICulture != null) {
+				th.CurrentUICulture = prevAppUICulture;
+				prevAppUICulture = null;
+			}
+		}
+
+		internal void OnStateExecuteEnter ()
+		{
+			SaveThreadCulture ();
 			_savedContext = HttpContext.Context;
 			HttpContext.Context = _Context;
 			HttpRuntime.TimeoutManager.Add (_Context);
@@ -831,8 +873,7 @@ namespace System.Web
 
 		internal void OnStateExecuteLeave ()
 		{
-			// TODO: Restore culture for the thread
-
+			RestoreThreadCulture ();
 			HttpRuntime.TimeoutManager.Remove (_Context);
 			HttpContext.Context = _savedContext;
 			if (null != _savedUser)  {