[Mono-aspnet-list] Profile_MigrateAnonymous() event in Global.asax

Mark Walmsley mail at markwalmsley.net
Tue Aug 11 11:53:37 EDT 2009



> Mark Walmsley wrote:
> > I am trying to use the Profile_MigrateAnonymous() event in a Global.asax
> > file, but it does not seem to fire.
> > 
> 
> Try to add this to global.asax and please file a bug regardless
> of whether the workaround works or not.
> 
> void Application_Start(object sender, EventArgs e)
> {
> 	((System.Web.Profile.ProfileModule)Modules["Profile"]).MigrateAnonymous
> 		+= Profile_MigrateAnonymous;
> }
> 

... I have tried this but got a null reference exception ... so I moved the
code
from the Start event to the Init event which gets called after all modules
are
already set up ... also tried out the AnonymousIdentification_Creating
event:

  void Application_Init(object sender, EventArgs e) {
    ((ProfileModule)Modules["Profile"]).MigrateAnonymous +=
Profile_MigrateAnonymous;
   
((AnonymousIdentificationModule)Modules["AnonymousIdentification"]).Creating
+= AnonymousIdentification_Creating;
  }
  void AnonymousIdentification_Creating(Object sender,
AnonymousIdentificationEventArgs e) {
    e.AnonymousID = "custom-anonymous-id";
  }
  void Profile_MigrateAnonymous(Object sender, ProfileMigrateEventArgs e) {
    ProfileBase anonymous = ProfileBase.Create(e.AnonymousID, false);
    ProfileBase user = ProfileBase.Create(e.Context.User.Identity.Name,
true);
    if ((anonymous != null) && (user != null)) {
      string colour = (string)(anonymous.GetPropertyValue("Colour"));
      if (!String.IsNullOrEmpty(colour)) {
        user.SetPropertyValue("Colour", colour);
      }
    }
    ProfileManager.DeleteProfile(e.AnonymousID);
    AnonymousIdentificationModule.ClearAnonymousIdentifier();
    Membership.DeleteUser(e.AnonymousID, true);
  }

This all compiles fine but none of the code seems to be executed when it
should be.

Also I put the following code in a test page ...

      protected void Page_Load(object sender, EventArgs e) {
        string[] modules =
HttpContext.Current.ApplicationInstance.Modules.AllKeys;
        string s = "";
        foreach (string module in modules) {
          s += (module + "<br>");
        }
        MyMessage.Text = s;
      }

The Profile and AnonymousIdentification modules are not listed if I add them
in the
application's Web.Config file ... but they are listed if I add them in the
server's
Web.Config file.

Where do I send bug reports ???
_______________________________________________
Mono-aspnet-list mailing list
Mono-aspnet-list at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-aspnet-list



-- 
View this message in context: http://www.nabble.com/Profile_MigrateAnonymous%28%29-event-in-Global.asax-tp24872437p24920364.html
Sent from the Mono - ASP.NET mailing list archive at Nabble.com.



More information about the Mono-aspnet-list mailing list