Click here to Skip to main content
15,883,901 members
Articles / Programming Languages / ASP
Article

Mutex Solution in ASP

Rate me:
Please Sign up or sign in to vote.
1.89/5 (8 votes)
10 Dec 2003 64.3K   646   23   9
ASP code for generating unique IDs

Introduction

This article is intended to solve the mutex problem, arising in huge websites, where a lot of information for each session user has to be unique. Here the solution for the  mutex problem is done using the ASP web technology. The same logic can be implemented in other technologies also. In fact this solution can even be implemented in client server applications.

Details

In a huge web application thousands of users log-in, and log-out in a hour from all over the world. Now, we some times need to provide them a unique ID instead of just a sessionID, and this cannot be done using any feature in IIS. Say, if we want to give them a unique ID for a table, then it is difficult to use the application.lock method, and then we need some extra mechanism to generate a unique ID. See Global.asa from the downloadable zip for details on how I have implemented the unique ID generation.

Sample Usage

HTML
<%=Application("recordsid")%>

History

  • December 12 2003 - First version

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Team Leader
United States United States
Populate

Around six years of experience in Software Engineering, system Developments, and Integrations.

Programming Languages: C#, VB.NET, ASP.NET, ASP, VB.

Database: SQL-Server 2005/2000/7.0, My-Sql.

Middle Tier: XML, MQ-SERIES

Operating Systems: IIS (3.0, 5.0, 6.0), APACHE (1.3-2.0)


Vista Gagdget, Widows SharePoint

Comments and Discussions

 
GeneralMy vote of 1 Pin
CoolVini6-Feb-09 13:52
CoolVini6-Feb-09 13:52 
GeneralRe: My vote of 1 Pin
Populate12318-Apr-09 21:23
Populate12318-Apr-09 21:23 
QuestionWhat's the point? Pin
Vince C.16-Dec-03 0:51
Vince C.16-Dec-03 0:51 
AnswerRe: What's the point? Pin
Populate12316-Dec-03 1:15
Populate12316-Dec-03 1:15 
GeneralRe: What's the point? Pin
Vince C.16-Dec-03 10:21
Vince C.16-Dec-03 10:21 
GeneralCan't understand... Pin
denic15-Dec-03 5:11
denic15-Dec-03 5:11 
GeneralRe: Can't understand... Pin
Populate12316-Dec-03 1:23
Populate12316-Dec-03 1:23 
Thogh I mail you, but for others, I put it for simplifications
=====================MAIL CONTENT============

UR QUERY:
=========
I don't understand this: after "application.lock" only one user can access the application variables, so if you assign session("") before application.unlock with an application variable you can be sure that no other user got the same application variable value. The "second" user should wait at the "application.lock line" until the "first" user has released the lock, so the second user can't get the same id value. Am I wrong about this? I'm quite interested in this, because I was well sure about that and if this is not true I have to recheck some software of mine...

My Comments:
============
Yes, when I use application.lock, no session user can not edit this variable, untill application.unlock. An the session variables 'Session("status")=true' used to exit out from while loops.

UR QUERY:
=========

Moreover, if you test application("ent") and application("work") outside an application.lock, you can't be sure they mantain the same value you checked "after" the check and before the lock, so the check is useless. Another user could be modified your application("ent") value "after" the first check and "before" the second check.


My Comments:
============
I used Application two variables. Now, think 2 user enter in the session, now two of them see 'Application("ent") = false' and 'Application("work") = false', now two of them get entered, now one of them only able to make 'Application("work") = true' and did the application.lock, in the meanwhile, sencond session user get allready it is lock, so he / she had to be wait untill application.unlock. I did not want to check this two application values in session, because in session they will get it false, and both of session user increment it(or may be the function will called), and mismash can happened. So that, I want to do it in one coomon area, that is in a function(). I have the problems, where more than 1000 user get in / out within 1 hr, and once in a time, they get same userID.

UR QUERY:
=========

Finally, in your function "GetnewId()" you don't assign any value to GetNewId, so it is not a function, it is a sub. in Sub Session_onStart your assignment
Session("ret")=GetNewId()
returns "empty" always. Maybe the code you submitted was not the original one?

My Comments:
============
well, in this function user / developer will assign the values according to need. I means may be some unique value will be generated for each visiting user. I just hard coded it into a variable, and increament it.

UR QUERY:
=========

My second remark is about this: if you write
1 Session("status")=false
2 while Session("status")=false
3 session("ret")=GetNewId
4 wend

line 3 is executed surely at least one time. You would be right if someone else could access the "Session()" variables, but only a user can access that, so it is impossible that two different users access the same session variable.

My Comments:
============
Session("status") will only access by one user. I just put this one, as to use it in while loop. Untill and unless user get the unique ID from databases(In actual projects), session user will be bounded on this while loop.

Now in while loop, we call the function, and here, I have to use application variables for this one.

Himadrish Laha
Blush | :O
Generalzip file empty Pin
msyoung15-Dec-03 4:14
msyoung15-Dec-03 4:14 
GeneralRe: zip file empty Pin
Populate12316-Dec-03 1:25
Populate12316-Dec-03 1:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.