Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jesper Hauge 298 posts 487 karma points c-trib
    Mar 19, 2010 @ 09:14
    Jesper Hauge
    0

    Why doesn't my AfterAddToCache event handler run?

    Working on a site with member logins I'd like to track last user login. So I bought access to umbraco.tv to see how that could be done (did also check out examples here at our.umbraco.

    So I have the following code, which is used in v4.0.3 site:

    using System;
    using umbraco.BusinessLogic;
    using umbraco.cms.businesslogic;
    using UmbracoMember = umbraco.cms.businesslogic.member.Member;
    
    namespace TI.Backend.Umbraco
    {
        public class MemberEvents : ApplicationBase
        {
            public MemberEvents()
            {
                UmbracoMember.AfterAddToCache += new UmbracoMember.AddingToCacheEventHandler(UmbracoMember_AfterAddToCache);
            }
    
            void UmbracoMember_AfterAddToCache(UmbracoMember sender, AddToCacheEventArgs e)
            {
                Log.Add(LogTypes.Debug, -1, "User login: " + sender.getProperty("firstname").Value.ToString());
                sender.getProperty("lastLogin").Value = DateTime.Now;
                sender.Save();
            }
        }
    }

    Which is placed in a project that is compiled into a dll and copied to the website /bin folder. But the code doesn't run when using the login page. There is no record in the log table, and the user lastLogin value isn't set after login.

    Can anybody see anything wrong with this code?

    Is it possible to run a member login without the AfterAddToCache event happening?

    Any ideas?

    Regards
    Jesper Hauge

  • Sebastiaan Janssen 5045 posts 15478 karma points MVP admin hq
    Mar 19, 2010 @ 09:44
    Sebastiaan Janssen
    0

     

    Well, maybe the AddToCache method is failing or being cancelled by another event handler. 

    Check out the trace for the page (add ?umbDebugShowTrace=true to the url) and find: "Member added to cache" to see if this works properly. The AfterAddToCache event happens very soon after that:

                        // Debug information
                        HttpContext.Current.Trace.Write("member",
                            string.Format("Member added to cache: {0}/{1} ({2})",
                                m.Text, m.LoginName, m.Id));
    
                        _memberCache["umbracoMembers"] = umbracoMembers;
    
    
                        FormsAuthentication.SetAuthCookie(m.LoginName, false);
    
                        m.FireAfterAddToCache(e);

    In any case, check the windows event log to see if you're getting any exceptions. Your code looks valid enough.

     

  • Jesper Hauge 298 posts 487 karma points c-trib
    Mar 19, 2010 @ 13:25
    Jesper Hauge
    0

    Thanks for your ideas Sebastiaan.

    After digging into this some more, I noticed that the functionality is actually configurable. You can create an attribute on the umbracoMemberShipProvider section in web.config, that points to the alias you want to store last login date in like this:

    <add name="UmbracoMembershipProvider" 
         type="umbraco.providers.members.UmbracoMembershipProvider"
         umbracoLastLoginPropertyTypeAlias="*yourAlias*" />

    This in effect removes the need for the code on the top.

    Regards
    Jesper Hauge

  • [email protected] 408 posts 2137 karma points MVP 7x c-trib
    Mar 26, 2010 @ 11:19
    jeffrey@umarketingsuite.com
    0

    Hi all,

    I have the same problem when I login. I use the code from umbraco.tv but when I login with a member nothing happens / the code isn't executed.

    Also I can't find "Member added to cache" in my trace. The begin of my trace looks like this

    aspx.page Begin PreInit
    umbracoInit handling request 1,99705971362164E-05 0,000020
    request handler current url '/profielen.aspx' 6,79768402521211E-05 0,000048
    umbracoRequestHandler Just before xPath query (True, '1167') 8,8715537278192E-05 0,000021
    umbracoRequestHandler After xPath query 0,000101389185460791 0,000013
    umbracoRequestHandler Access checking started 0,000130192931330334 0,000029
    umbracoRequestHandler Page protected 0,000146323029017278 0,000016
    umbracoRequestHandler Access checking ended 0,00645050287499789 0,006304
    umbracoInit Done handling request 0,00647700232119787 0,000026
    umbracoPage Element loaded: meta_title 0,00652424046442392 0,000047
    umbracoPage Element loaded: meta_description 0,00653960246222101 0,000015
    umbracoPage Element loaded: umbracoNaviHide 0,00655150801051375 0,000012
    umbracoPage Pagedata loaded for Profielen (ID: 1167, Version: 42c722d4-7582-4f7e-8304-92252d167e40) 0,00656571785847606 0,000014
    aspx.page End PreInit 0,00692902910637723 0,000363
    aspx.page Begin Init 0,00694592730395402 0,000017

     

    Somebody any ideas?


    Jeffrey

  • Matthew J Cowan 2 posts 22 karma points
    Apr 10, 2010 @ 01:58
    Matthew J Cowan
    0

    I just ran into this problem with my new install.

    In order for the New event to work, i had to add the defaultMemberTypeAlias attribute to the membership provider tag. Only then would the New event fire in the class.

    In order to capture the lastLogin time stamp, i had to use the umbracoLastLoginPropertyTypeAlias. The "Member.AfterAddToCache" event doesn't seem to fire for me at all. I haven't tested any of the other events.

    I'm using v. 4.0.3...

     

  • Jesper Hauge 298 posts 487 karma points c-trib
    Apr 10, 2010 @ 12:07
    Jesper Hauge
    0

    I'll check to see if theres an issue about this in codeplex, or add one.

    .Jesper Hauge

Please Sign in or register to post replies

Write your reply to:

Draft