2008-11-06 Marek Habersack <mhabersack@novell.com>
[mono.git] / mcs / class / System.Web / System.Web.Security / AnonymousIdentificationModule.cs
index 896b5c6d5321066c83c28604410d967993b11c3a..b8e7bfa11a4c4284930441cb4f82ff7e5ba63055 100644 (file)
@@ -31,6 +31,7 @@
 #if NET_2_0
 
 using System;
+using System.ComponentModel;
 using System.Web;
 using System.Web.Configuration;
 using System.Text;
@@ -38,9 +39,15 @@ using System.Text;
 namespace System.Web.Security {
 
        public sealed class AnonymousIdentificationModule : IHttpModule {
-
+               static readonly object creatingEvent = new object ();
+               
                HttpApplication app;
-               public event AnonymousIdentificationEventHandler Creating;
+               EventHandlerList events = new EventHandlerList ();
+               
+               public event AnonymousIdentificationEventHandler Creating  {
+                       add { events.AddHandler (creatingEvent, value); }
+                       remove { events.RemoveHandler (creatingEvent, value); }
+               }
 
                public static void ClearAnonymousIdentifier ()
                {
@@ -78,9 +85,10 @@ namespace System.Web.Security {
                        }
 
                        if (anonymousID == null) {
-                               if (Creating != null) {
+                               AnonymousIdentificationEventHandler eh = events [creatingEvent] as AnonymousIdentificationEventHandler;
+                               if (eh != null) {
                                        AnonymousIdentificationEventArgs e = new AnonymousIdentificationEventArgs (HttpContext.Current);
-                                       Creating (this, e);
+                                       eh (this, e);
 
                                        anonymousID = e.AnonymousID;
                                }
@@ -106,13 +114,26 @@ namespace System.Web.Security {
                        }
                }
 
+#if TARGET_JVM
                static AnonymousIdentificationSection Config
                {
                        get
                        {
-                               return (AnonymousIdentificationSection) WebConfigurationManager.GetSection ("system.web/anonymousIdentification");
+                               AnonymousIdentificationSection config = (AnonymousIdentificationSection) AppDomain.CurrentDomain.GetData ("Anonymous.Config");
+                               if (config == null) {
+                                       lock (typeof (AnonymousIdentificationModule)) {
+                                               config = (AnonymousIdentificationSection) AppDomain.CurrentDomain.GetData ("Anonymous.Config");
+                                               if (config == null)
+                                                       config = (AnonymousIdentificationSection) WebConfigurationManager.GetSection ("system.web/anonymousIdentification");
+                                               AppDomain.CurrentDomain.SetData ("Anonymous.Config", config);
+                                       }
+                               }
+                               return config;
                        }
                }
+#else
+               static AnonymousIdentificationSection Config = (AnonymousIdentificationSection) WebConfigurationManager.GetSection ("system.web/anonymousIdentification");
+#endif
        }
 }
 #endif