Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create a unique number each time web page is opened

Status
Not open for further replies.

davman2002

Programmer
Nov 4, 2002
75
US
I need to know if there is a way in ASP to have the web page create a new number (preferrably sequential) every time the page is loaded. I want to use this number as a session ID. We have over 2000 computers and if I open the page I should get 1 then if anyone else opens the page they would get 2 etc... Any help is appreciated.
 
When your computer connects to an IIS server (ie ASP pages) the server automatically attemptsd to assign you a session id and store it in a cookie. This is how the session information your storing on the server is matched up with the user. Whether or not they have cookies turned on this value is generated. If they don't have cookies they geta new one each time, if they do have cookies they keep the first one they get. If you need to work in a cookie free zone you can still take advantage of the session id by grabbing it on the very first page of the site and assigning it to a hidden field. This way you have your (mostly) unique sequential (until someone with cookies visits and eats 15 of your sequential numbers) number to work with.

More information on sessions and session id's here:

As for generating your own unique number, you will need to store the current value somewhere. I would suggest in an application variable. Set it up so that On Application end you write the value to a text file, on application start read the value from the text file and place it in an application variable. Now every timesomeone visits your site to start a session, put a read write lock on the variable, read it, assign it to your user, increment it, set it back into the application variable, release the lock. This will give you sequential unique id's.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top