How do I call AnonymousIdentification_Creating

Last post 11-12-2009 9:52 AM by duckkiller53. 5 replies.

Sort Posts:

  • How do I call AnonymousIdentification_Creating

    11-06-2009, 4:29 PM

     Could someone Please help. I am reading the book Professional ASP.NET 3.5 BY wrox.  In the section on Personalizaion and in particular "Working with Anonymous Identification" the Author states that you can create your own unique AnonymousID by using the event AnonymousIdentification_Creating from the Global.asax.  In the Authors words you just create the event using the event delegate of type AnonymousIdentificationEventArgs as listed below.

    Public Sub AnonymousIdentification_Creating(ByVal sender As Object, ByVal e As AnonymousIDentificationEventArgs)


    e.AnonymousID = "Bubbles " & DateTime.Now()


    End Sub


    Then the Author just said that by setting the e.AnonymoudID you can set your own unique ID vs a GUID.


    ***Question*** The author never states what a Global.asax is?  He just make the statement it's there, what is it?

    ***Question*** How do you call this public sub AnonymouseIdentification_Creating() I have tried just calling it from code

                                ie Protected Sub btnText_Click(ByVal sender As Object, ByVal e As System.EventArgs)

                                                               AnonymouseIdentification_creating()  // errors.

                                                    End Sub

    Thanks


    Dave.



    Duckkiller53

    Duckkiller53@gmail.com
  • Re: How do I call AnonymousIdentification_Creating

    11-06-2009, 5:39 PM

    I have just found that the Global.asax file, also known as the ASP.NET application file, is an optional file that contains code for responding to application-level events raised by ASP.NET.  I placed the AnonymousIdentification_Creating() sub in that file and what do you know it worked.  But the book also stated that you can place this code in your page code if you want this done at the page leve.  If so my question still stands. 


    "HOW DO YOU CALL IT"


    Duckkiller53

    Duckkiller53@gmail.com
  • Re: How do I call AnonymousIdentification_Creating

    11-08-2009, 4:53 AM
    Answer
    • Contributor
      5,226 point Contributor
    • RickNZ
    • Member since 01-01-2009, 8:43 AM
    • Nelson, New Zealand
    • Posts 872

    You don't call it yourself.  It's an event handler, and gets called automatically at the appropriate time.

    The runtime gets tricky with some of these handlers; it looks for them using reflection, and if they're present, then they automatically get registered for you.  Page_Load() at the Page level works the same way.

    See also:

    http://msdn.microsoft.com/en-us/library/system.web.security.anonymousidentificationmodule.creating.aspx


  • Re: How do I call AnonymousIdentification_Creating

    11-09-2009, 2:13 PM


    Thanks for the insight about the AnonymouseIdentification_Creating() event handler getting called automaticlly.  What still confuses me is how do you use it if you can't control when it is called.  What I mean is, say for example you have a routine that will convert an anonymous user to a registered user (shopping cart situation) and you have a button that the user is to click when there finished registering.  How would asp.net know when to fire the AnonymouseIdentification_Creating() to convert the user.


    Dave.

    Duckkiller53

    Duckkiller53@gmail.com
  • Re: How do I call AnonymousIdentification_Creating

    11-09-2009, 6:24 PM
    Answer
    • Contributor
      5,226 point Contributor
    • RickNZ
    • Member since 01-01-2009, 8:43 AM
    • Nelson, New Zealand
    • Posts 872

    I don't understand the details of what you're trying to do, but the usual flow for using this event might be something like: your button sets a cookie that directly or indirectly contains the registered user information.  Then, on the next request, as part of the processing pipeline, the AnonymousIdentification_Creating() event is called by the runtime during the PostAuthenticateRequest event, when the anonymous user is created.  You then set the AnonymousID field to the value from your cookie (if it's present).

    The reason it usually works like this is because the authentication process needs to happen for every request, not just when the user logs-on.

    Also, I'm not sure I would handle the scenario you described this way... but that's a whole other thing...




  • Re: How do I call AnonymousIdentification_Creating

    11-12-2009, 9:52 AM

    Well after reading and reading I finally understand the Provider model and asp.net Personalization.  Thanks for all the help, and to anyone else wondering about this even, i is alled automaticlly when a user ( who doesn't have a cookie previously registered for a web site ) and your viewing it as an Anonymous user, the event will fire Either by placing it in the global.asax file or at the page level.


    Thanks to everyone who took the time to help explain this to a complete newbee!


    Dave.

    Duckkiller53

    Duckkiller53@gmail.com
Page 1 of 1 (6 items)