But I don't seem to be firing that AfterAddToCache member event when my member logs in.
I'm running 4.8.1. I noticed that ApplicationBase has been deprecated in favour of ApplicationStartupHandler, so I'm using that instead:
using System;
using umbraco.businesslogic;
using umbraco.cms.businesslogic.member;
namespace zo.umbraco.LastLogin
{
public class MemberEvent : ApplicationStartupHandler
{
public MemberEvent()
{
Member.AfterAddToCache += new Member.AddingToCacheEventHandler(Member_AfterAddToCache);
}
void Member_AfterAddToCache(Member sender, global::umbraco.cms.businesslogic.AddToCacheEventArgs e)
{
sender.getProperty("lastLogin").Value = DateTime.Now;
sender.Save();
}
}
}
I build this assembly (empty website project, with just the single .cs file), and copy the .dll into the bin folder of the umbraco install, and restart the app.
I then have a member type with an additional property: lastLogin of type datepicker with time.
I tried adding exceptions to my code above, just to see if it's firing, as well as attaching to the webmatrix instance with the VS2010 debugger, and in both cases, it looks like my code just isn't firing.
I looked through the Member class a bit, and see that many properties are deprecated ("MakeNew", "GetMemberFromEmail", etc etc), so I was worried that maybe that Umbraco tv video is just out of date but the events all seem to be the same as they were then.
Can someone please tell me how to subscribe to an event in umbraco 4.8.1 so that my code will fire, and also how to fire code when a member logs into secured pages in umbraco
I haven't tried the new ApplicationStartupHandler yet, but if that doesn't work you could still try the ApplicationBase off course.
The Member class properties might be deprecated, but they still work and I'm still using them if I'm using members in Umbraco. There's even a little discussion about it here: http://issues.umbraco.org/issue/U4-63.
Thanks for your guidance, but I'm still having issues. I reverted back to inheriting from ApplicationBase, but the Member events are still not being hit. At first I thought maybe my whole class was not firing, so I also added some logging on a document event per below:
using System;
//using umbraco.businesslogic;
using umbraco.cms.businesslogic.member;
using umbraco.cms.businesslogic.web;
using umbraco.BusinessLogic;
namespace Samples
{
//public class MemberEvent : ApplicationStartupHandler
public class MemberEvent : umbraco.BusinessLogic.ApplicationBase
{
public MemberEvent()
{
Member.AfterAddToCache += new Member.AddingToCacheEventHandler(Member_AfterAddToCache);
Document.BeforePublish += new Document.PublishEventHandler(Document_BeforePublish);
Member.BeforeAddToCache += new Member.AddingToCacheEventHandler(Member_BeforeAddToCache);
}
void Member_BeforeAddToCache(Member sender, umbraco.cms.businesslogic.AddToCacheEventArgs e)
{
Log.Add(LogTypes.Debug, sender.Id, "Member_BeforeAddToCache");
}
void Document_BeforePublish(Document sender, umbraco.cms.businesslogic.PublishEventArgs e)
{
Log.Add(LogTypes.Debug, sender.Id, "Document_BeforePublish");
}
void Member_AfterAddToCache(Member sender, global::umbraco.cms.businesslogic.AddToCacheEventArgs e)
{
Log.Add(LogTypes.Debug, sender.Id, "Member_AfterAddToCache");
sender.getProperty("lastLogin").Value = DateTime.Now;
sender.Save();
}
}
}
These new document event *IS BEING FIRED*; when I publish a document, it ends up in the log. The member events still are not. Has something changed in 4.8.1 that would cause this? I've never actually attached to these events before (in previous versions of Umbraco), so I don't know that it ever worked... Is there another way to do this that I should be doing?
Add Last Login to member
I've followed the instructions from the Umbraco tv tutorial at:
http://umbraco.com/help-and-support/video-tutorials/developing-with-umbraco/events/set-a-last-login-date-on-member-on-login.aspx
But I don't seem to be firing that AfterAddToCache member event when my member logs in.
I'm running 4.8.1. I noticed that ApplicationBase has been deprecated in favour of ApplicationStartupHandler, so I'm using that instead:
I build this assembly (empty website project, with just the single .cs file), and copy the .dll into the bin folder of the umbraco install, and restart the app.
I then have a member type with an additional property: lastLogin of type datepicker with time.
I tried adding exceptions to my code above, just to see if it's firing, as well as attaching to the webmatrix instance with the VS2010 debugger, and in both cases, it looks like my code just isn't firing.
I looked through the Member class a bit, and see that many properties are deprecated ("MakeNew", "GetMemberFromEmail", etc etc), so I was worried that maybe that Umbraco tv video is just out of date but the events all seem to be the same as they were then.
Can someone please tell me how to subscribe to an event in umbraco 4.8.1 so that my code will fire, and also how to fire code when a member logs into secured pages in umbraco
Thanks in advance!
Jonathan
Hello,
I haven't tried the new ApplicationStartupHandler yet, but if that doesn't work you could still try the ApplicationBase off course.
The Member class properties might be deprecated, but they still work and I'm still using them if I'm using members in Umbraco. There's even a little discussion about it here: http://issues.umbraco.org/issue/U4-63.
Jeroen
Hi Jeroen,
Thanks for your guidance, but I'm still having issues. I reverted back to inheriting from ApplicationBase, but the Member events are still not being hit. At first I thought maybe my whole class was not firing, so I also added some logging on a document event per below:
These new document event *IS BEING FIRED*; when I publish a document, it ends up in the log. The member events still are not. Has something changed in 4.8.1 that would cause this? I've never actually attached to these events before (in previous versions of Umbraco), so I don't know that it ever worked... Is there another way to do this that I should be doing?
Thanks in advance
Jonathan
Hello,
I've never used those events so I don't know when they are fired. Perhaps the member has other events you can use?
Jeroen
is working on a reply...