Copied to clipboard

Flag this post as spam?

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


  • Dan 1288 posts 3921 karma points c-trib
    Aug 29, 2010 @ 18:18
    Dan
    0

    Create unique id for each site visitor

    Hi,

    I have the requirement to build a site in Umbraco which will assign a unique id to each site visitor.  The visitors may browse the website and store various pieces of information (for which I'll probably use base to write their data to a temporary database table).  The visitor may then choose to register as a member and have their data permanently stored.  They may also log-in later to retrieve this stored information.

    Ordinarily, I'd do the temporary data storage with cookies, but there may be 70 or more individual pieces of data stored by each user, and I suspect cookies won't be up to the job (had issues before with limits on both number of cookies and cookie size across different browsers) hence the reason for using base and a temp database table.  If there's a better way then I'm open to suggestions :)

    However, before I do anything I need to know the best way to reliably and efficiently create a unique id for each visitor.  How is this best done?  I could perform a check on each base request to see if there's a session id assigned to the user, and if not, create one, but this would mean that there are an awful lot of unnecessary checks performed as the user navigates the site and their choices stored (it would only be the first one which would actually do anything).  I thought there might be a better way to only create the session id only once, then use base purely to log the piece of information with that id in the temp db table.

    Thanks for any pointers folks.

     

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Aug 29, 2010 @ 18:25
    Morten Bock
    0

    I think I would go with the cookie for storing the ID. So on each request, check if there is an ID in the cookie. If not, create one. I don't think that there is any way to do that more efficiently. 

  • Dan 1288 posts 3921 karma points c-trib
    Aug 29, 2010 @ 18:38
    Dan
    0

    Thanks Morten,

    Where in the process would it be best to create this though?  On each base request, or is there a general process which is called when the site is visited in which this can be called?  Apologies if this is a dense question, I'm mainly front-end, so not too clued up on the range of .NET possibilities for doing this :)

  • Dan 1288 posts 3921 karma points c-trib
    Aug 29, 2010 @ 18:50
    Dan
    0

    The other option is to go the pure javascript route of course, and just call an "if" statement in a master js file called on each page load event.  I wonder if there's a .NET way to just call this once?

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Aug 29, 2010 @ 19:20
    Morten Bock
    0

    Well, there are a few way to do this.

    1: You could put a usercontrol in your masterpage, which will will then set the cookie if it does not exist. Since your html page will probably be the first thing visited by the user, your /base methods would just need to read the cookie, since they can probably rely on it always being there.

    2: An httpmodule could make the check on any request to the site, so the cookie will be set no matter what kind of request is the first the user makes.

    The javascript approach will probably work just fine as well, and will also be very easy to implement if you are mostly a front end dev. You wouldn't even have to wait for the onLoad event, just set it straight away, so that any subsequent javascript ajax requests will have that cookie set.

    If by "I wonder if there's a .NET way to just call this once?" you mean that the code will only run the first time the user visits the site, then no. The nature of html/http is that it is stateless, so you will need to do the check on every single request, no matter which of the methods you choose.

  • Dan 1288 posts 3921 karma points c-trib
    Aug 29, 2010 @ 19:25
    Dan
    0

    Cool, thanks Morten.  I think I'll stick to the .js approach; keep it simple.

Please Sign in or register to post replies

Write your reply to:

Draft