Пример #1
0
        /// <summary>
        /// Method is used when logging a member in.
        /// 
        /// Adds the member to the cache of logged in members
        /// 
        /// Uses cookiebased recognition
        /// 
        /// Can be used in the runtime
        /// </summary>
        /// <param name="m">The member to log in</param>
        public static void AddMemberToCache(Member m)
        {

            if (m != null)
            {
                AddToCacheEventArgs e = new AddToCacheEventArgs();
                m.FireBeforeAddToCache(e);

                if (!e.Cancel)
                {
                    // Add cookie with member-id, guid and loginname
                    // zb-00035 #29931 : cleanup member state management
                    // NH 4.7.1: We'll no longer use legacy cookies to handle Umbraco Members
                    //SetMemberState(m);

                    FormsAuthentication.SetAuthCookie(m.LoginName, true);

                    //cache the member
                    var cachedMember = Cache.GetCacheItem<Member>(GetCacheKey(m.Id), m_Locker,
                        TimeSpan.FromMinutes(30),
                        delegate
                        {
                            // Debug information
                            HttpContext.Current.Trace.Write("member",
                                string.Format("Member added to cache: {0}/{1} ({2})",
                                    m.Text, m.LoginName, m.Id));

                            return m;
                        });

                    m.FireAfterAddToCache(e);
                }
            }

        }
Пример #2
0
 protected virtual void FireBeforeAddToCache(AddToCacheEventArgs e)
 {
     if (BeforeAddToCache != null)
     {
         BeforeAddToCache(this, e);
     }
 }
Пример #3
0
 protected virtual void FireAfterAddToCache(AddToCacheEventArgs e)
 {
     if (AfterAddToCache != null)
     {
         AfterAddToCache(this, e);
     }
 }
Пример #4
0
        public static void AddMemberToCache(Member m, bool UseSession, TimeSpan TimespanForCookie)
        {
            if (m != null)
            {
                var e = new AddToCacheEventArgs();
                m.FireBeforeAddToCache(e);

                if (!e.Cancel)
                {
                    // zb-00035 #29931 : cleanup member state management
                    // NH 4.7.1: We'll no longer use Umbraco legacy cookies to handle members
                    //SetMemberState(m, UseSession, TimespanForCookie.TotalDays);

                    FormsAuthentication.SetAuthCookie(m.LoginName, !UseSession);

                    //cache the member
                    var cachedMember = ApplicationContext.Current.ApplicationCache.GetCacheItem(
                        GetCacheKey(m.Id),
                        TimeSpan.FromMinutes(30),
                        () =>
                            {
                                // Debug information
                                HttpContext.Current.Trace.Write("member",
                                                                string.Format("Member added to cache: {0}/{1} ({2})",
                                                                              m.Text, m.LoginName, m.Id));

                                return m;
                            });

                    m.FireAfterAddToCache(e);
                }

            }
        }