Author: krasnov
Date: 2006-11-05 09:02:13 -0500 (Sun, 05 Nov 2006)
New Revision: 67375

Modified:
   
trunk/mcs/class/System.Web/System.Web.Security/AnonymousIdentificationModule.cs
   trunk/mcs/class/System.Web/System.Web.Security/ChangeLog
Log:
* AnonymousIdentificationModule.cs: fixed anonymous id cookie


Modified: 
trunk/mcs/class/System.Web/System.Web.Security/AnonymousIdentificationModule.cs
===================================================================
--- 
trunk/mcs/class/System.Web/System.Web.Security/AnonymousIdentificationModule.cs 
    2006-11-05 13:32:07 UTC (rev 67374)
+++ 
trunk/mcs/class/System.Web/System.Web.Security/AnonymousIdentificationModule.cs 
    2006-11-05 14:02:13 UTC (rev 67375)
@@ -30,22 +30,24 @@
 
 #if NET_2_0
 
+using System;
 using System.Web;
 using System.Web.Configuration;
+using System.Text;
 
 namespace System.Web.Security {
 
        public sealed class AnonymousIdentificationModule : IHttpModule {
 
+               HttpApplication app;
                public event AnonymousIdentificationEventHandler Creating;
-               
+
                public static void ClearAnonymousIdentifier ()
                {
                        HttpContext c = HttpContext.Current;
-                       SystemWebSectionGroup g = 
(SystemWebSectionGroup)WebConfigurationManager.GetSection ("system.web");
 
-                       if (!g.AnonymousIdentification.Enabled
-                           || false /* XXX The user for the current request is 
anonymous */)
+                       if (Config == null || !Config.Enabled)
+                               /* XXX The user for the current request is 
anonymous */
                                throw new NotSupportedException ();
                }
 
@@ -61,6 +63,7 @@
                        app.PostAuthenticateRequest += OnEnter;
                }
 
+               [MonoTODO ("cookieless userid")]
                void OnEnter (object source, EventArgs eventArgs)
                {
                        if (!Enabled)
@@ -68,27 +71,47 @@
 
                        string anonymousID = null;
 
-                       if (Creating != null) {
-                               AnonymousIdentificationEventArgs e = new 
AnonymousIdentificationEventArgs (HttpContext.Current);
-                               Creating (this, e);
+                       HttpCookie cookie = app.Request.Cookies 
[Config.CookieName];
+                       if (cookie == null || (cookie.Expires != 
DateTime.MinValue && cookie.Expires < DateTime.Now)) {
+                               if (Creating != null) {
+                                       AnonymousIdentificationEventArgs e = 
new AnonymousIdentificationEventArgs (HttpContext.Current);
+                                       Creating (this, e);
 
-                               anonymousID = e.AnonymousID;
-                       }
+                                       anonymousID = e.AnonymousID;
+                               }
 
-                       if (anonymousID == null)
-                               anonymousID = Guid.NewGuid().ToString();
+                               if (anonymousID == null)
+                                       anonymousID = Guid.NewGuid ().ToString 
();
 
-                       app.Request.AnonymousID = anonymousID;
+                               app.Request.AnonymousID = anonymousID;
+
+                               HttpCookie newCookie = new HttpCookie 
(Config.CookieName);
+                               newCookie.Path = app.Request.ApplicationPath;
+                               newCookie.Expires = DateTime.Now + 
Config.CookieTimeout;
+                               newCookie.Value = Convert.ToBase64String 
(Encoding.Unicode.GetBytes (anonymousID));
+                               app.Response.AppendCookie (newCookie);
+                       }
+                       else {
+                               app.Request.AnonymousID = 
Encoding.Unicode.GetString (Convert.FromBase64String (cookie.Value));
+                       }
                }
 
                public static bool Enabled {
                        get {
-                               SystemWebSectionGroup g = 
(SystemWebSectionGroup)WebConfigurationManager.GetSection ("system.web");
-                               return g.AnonymousIdentification.Enabled;
+                               if (Config == null)
+                                       return false;
+
+                               return Config.Enabled;
                        }
                }
 
-               HttpApplication app;
+               static AnonymousIdentificationSection Config
+               {
+                       get
+                       {
+                               return (AnonymousIdentificationSection) 
WebConfigurationManager.GetSection ("system.web/anonymousIdentification");
+                       }
+               }
        }
 }
 #endif

Modified: trunk/mcs/class/System.Web/System.Web.Security/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web.Security/ChangeLog    2006-11-05 
13:32:07 UTC (rev 67374)
+++ trunk/mcs/class/System.Web/System.Web.Security/ChangeLog    2006-11-05 
14:02:13 UTC (rev 67375)
@@ -1,5 +1,9 @@
 2006-11-05 Vladimir Krasnov <[EMAIL PROTECTED]>
 
+       * AnonymousIdentificationModule.cs: fixed anonymous id cookie
+
+2006-11-05 Vladimir Krasnov <[EMAIL PROTECTED]>
+
        * MembershipProvider.cs, SqlMembershipProvider.cs:
        refactoring of DecryptPassword and EncryptPassword methods according
        to documentation

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to