One person at a time...

Discussion in 'ASP General' started by deostroll, Jun 22, 2007.

  1. deostroll

    deostroll Guest

    Is there any way I can write a asp script such that if one user is
    using it no other person can access that page until the processing is
    complete...?
    --deostroll
    deostroll, Jun 22, 2007
    #1
    1. Advertising

  2. deostroll wrote:
    > Is there any way I can write a asp script such that if one user is
    > using it no other person can access that page until the processing is
    > complete...?
    > --deostroll


    Just to be clear, there is no such thing as an "asp script". ASP is a
    "platform" that supports the execution of various scripting languages,
    including vbscript and jscript. I will assume you are talking about
    vbscript, although the answer is similar for jscript. There are several
    options, but i think the simplest is to utilize an Application variable:

    <%
    application.lock
    application("I_am_locked") = true
    application.unlock

    'do stuff

    application.lock
    application("I_am_locked") = false
    application.unlock
    %>

    You can find the ASP Scripting documentation here:
    http://msdn.microsoft.com/library/en-us/iissdk/html/2c40c3cf-90eb-41ca-ae2a-0ef33a651779.asp
    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
    Bob Barrows [MVP], Jun 22, 2007
    #2
    1. Advertising

  3. deostroll wrote:
    > Is there any way I can write a asp script such that if one user is
    > using it no other person can access that page until the processing is
    > complete...?
    > --deostroll

    Oh wait, it's a little more complex than that. I will reply later with a
    better reply if nobody beats me to it.
    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
    Bob Barrows [MVP], Jun 22, 2007
    #3
  4. deostroll

    deostroll Guest

    On Jun 22, 10:08 pm, "Bob Barrows [MVP]" <>
    wrote:
    > deostroll wrote:
    > > Is there any way I can write a asp script such that if one user is
    > > using it no other person can access that page until the processing is
    > > complete...?
    > > --deostroll

    >
    > Oh wait, it's a little more complex than that. I will reply later with a
    > better reply if nobody beats me to it.
    > --
    > Microsoft MVP - ASP/ASP.NET
    > Please reply to the newsgroup. This email account is my spam trap so I
    > don't check it very often. If you must reply off-line, then remove the
    > "NO SPAM"


    Hey bob, what if I just had a text file (locked.txt) that would read
    either a 'yes' or 'no'. No in my asp code I could do some ordinary
    file handling to access that text file. I can read the content of the
    text file. If it reads 'no' then I can

    a) truncate the text file and write yes into it, and
    b) go on with the processing

    or else give a message - "sorry this page is locked!!!"?
    deostroll, Jun 22, 2007
    #4
  5. deostroll wrote:
    > Is there any way I can write a asp script such that if one user is
    > using it no other person can access that page until the processing is
    > complete...?
    > --deostroll


    I think this will work better. I've incorporated a 15 second timeout - you
    can adjust it to whatever fits your scalability needs:

    <%
    dim guid, TypeLib, start, t
    'generate a unique id (GUID)
    Set TypeLib = CreateObject("Scriptlet.TypeLib")
    guid=Left(CStr(TypeLib.Guid), 38)

    start=Now()
    Do Until LockMe(guid) or t>15
    t=DateDiff("s",start, Now())
    Loop

    'do stuff

    UnLockMe

    Function LockMe(pGuid)
    if application("LockedBy") <> "" then
    LockMe=false
    else
    application.lock
    if application("LockedBy") <> "" then
    LockMe=false
    Application.Unlock
    else
    application("LockedBy") = pGuid
    application.unlock
    LockMe=true
    end if
    end if
    End Function

    Sub UnLockMe()
    application.lock
    application("LockedBy") = ""
    application.unlock
    End Sub
    %>

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
    Bob Barrows [MVP], Jun 22, 2007
    #5
  6. deostroll wrote:
    > On Jun 22, 10:08 pm, "Bob Barrows [MVP]" <>
    > wrote:
    >> deostroll wrote:
    >>> Is there any way I can write a asp script such that if one user is
    >>> using it no other person can access that page until the processing
    >>> is complete...?
    >>> --deostroll

    >>
    >> Oh wait, it's a little more complex than that. I will reply later
    >> with a better reply if nobody beats me to it.
    >> --
    >> Microsoft MVP - ASP/ASP.NET
    >> Please reply to the newsgroup. This email account is my spam trap so
    >> I don't check it very often. If you must reply off-line, then remove
    >> the "NO SPAM"

    >
    > Hey bob, what if I just had a text file (locked.txt) that would read
    > either a 'yes' or 'no'. No in my asp code I could do some ordinary
    > file handling to access that text file. I can read the content of the
    > text file. If it reads 'no' then I can
    >
    > a) truncate the text file and write yes into it, and
    > b) go on with the processing
    >
    > or else give a message - "sorry this page is locked!!!"?


    It's more complicated than that. What if another thread accesses the text
    file before you save your change to it? The other thread will still see that
    it says "no", change it to "yes" and go on its merry way.

    You could utilize a GUID the way i did in my second example. Of course, with
    text files, you need to worry about file-system permissions. Plus
    performance: disk i/o is slower than accessing application variables.
    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
    Bob Barrows [MVP], Jun 22, 2007
    #6
  7. deostroll

    deostroll Guest

    On Jun 22, 10:49 pm, "Bob Barrows [MVP]" <>
    wrote:
    > deostroll wrote:
    > > On Jun 22, 10:08 pm, "Bob Barrows [MVP]" <>
    > > wrote:
    > >> deostroll wrote:
    > >>> Is there any way I can write a asp script such that if one user is
    > >>> using it no other person can access that page until the processing
    > >>> is complete...?
    > >>> --deostroll

    >
    > >> Oh wait, it's a little more complex than that. I will reply later
    > >> with a better reply if nobody beats me to it.
    > >> --
    > >> Microsoft MVP - ASP/ASP.NET
    > >> Please reply to the newsgroup. This email account is my spam trap so
    > >> I don't check it very often. If you must reply off-line, then remove
    > >> the "NO SPAM"

    >
    > > Hey bob, what if I just had a text file (locked.txt) that would read
    > > either a 'yes' or 'no'. No in my asp code I could do some ordinary
    > > file handling to access that text file. I can read the content of the
    > > text file. If it reads 'no' then I can

    >
    > > a) truncate the text file and write yes into it, and
    > > b) go on with the processing

    >
    > > or else give a message - "sorry this page is locked!!!"?

    >
    > It's more complicated than that. What if another thread accesses the text
    > file before you save your change to it? The other thread will still see that
    > it says "no", change it to "yes" and go on its merry way.
    >
    > You could utilize a GUID the way i did in my second example. Of course, with
    > text files, you need to worry about file-system permissions. Plus
    > performance: disk i/o is slower than accessing application variables.
    > --
    > Microsoft MVP - ASP/ASP.NET
    > Please reply to the newsgroup. This email account is my spam trap so I
    > don't check it very often. If you must reply off-line, then remove the
    > "NO SPAM"


    Thanx bob, that was some real help.

    -deostroll
    deostroll, Jun 25, 2007
    #7
  8. "Bob Barrows [MVP]" <> wrote in message
    news:...
    > deostroll wrote:
    > > Is there any way I can write a asp script such that if one user is
    > > using it no other person can access that page until the processing is
    > > complete...?
    > > --deostroll

    >
    > I think this will work better. I've incorporated a 15 second timeout - you
    > can adjust it to whatever fits your scalability needs:
    >
    > <%
    > dim guid, TypeLib, start, t
    > 'generate a unique id (GUID)
    > Set TypeLib = CreateObject("Scriptlet.TypeLib")
    > guid=Left(CStr(TypeLib.Guid), 38)
    >
    > start=Now()
    > Do Until LockMe(guid) or t>15
    > t=DateDiff("s",start, Now())
    > Loop
    >
    > 'do stuff
    >
    > UnLockMe
    >
    > Function LockMe(pGuid)
    > if application("LockedBy") <> "" then
    > LockMe=false
    > else
    > application.lock
    > if application("LockedBy") <> "" then
    > LockMe=false
    > Application.Unlock
    > else
    > application("LockedBy") = pGuid
    > application.unlock
    > LockMe=true
    > end if
    > end if
    > End Function
    >
    > Sub UnLockMe()
    > application.lock
    > application("LockedBy") = ""
    > application.unlock
    > End Sub
    > %>
    >


    Bob,

    I'm not sure I understand why you're using a GUID? Session.SessionID or
    some other ID that would help identify the user, client or session currently
    locking for diagnostic purposes would be better.

    Also after your code times out failing to get a lock the code goes on to to
    it's stuff anyway.
    Anthony Jones, Jun 26, 2007
    #8
  9. Anthony Jones wrote:
    > "Bob Barrows [MVP]" <> wrote in message
    > news:...
    >> 'generate a unique id (GUID)
    >> Set TypeLib = CreateObject("Scriptlet.TypeLib")
    >> guid=Left(CStr(TypeLib.Guid), 38)


    > Bob,
    >
    > I'm not sure I understand why you're using a GUID? Session.SessionID
    > or some other ID that would help identify the user, client or session
    > currently locking for diagnostic purposes would be better.
    >>


    Not everyone uses sessions. GUIDs can be used whether sessions are enabled
    or not.

    I was just trying to create a generic solution, trusting that the OP would
    be able to adapt it to his situation. To amplify:

    If you're using sessions, and have taken precautions against
    session-hijacking, use SessionID instead of Guid
    If you are on a LAN or WAN, and your site has anonymous disabled and
    Integrated autentication enabled, use the user's login name instead of the
    GUID
    If you are using Basic Authentication and your user logs into a database
    that returns a unique user id, use the id instead of the GUID


    >> start=Now()
    >> Do Until LockMe(guid) or t>15
    >> t=DateDiff("s",start, Now())
    >> Loop

    'do stuff
    <snip>
    >
    > Also after your code times out failing to get a lock the code goes on
    > to to it's stuff anyway.


    Oops ... er ... I left that as an exercise for the reader ... yeah, that's
    the ticket!
    Come on reader (not you, Anthony - I know you know the answer <grin>)! What
    has to be changed in the above snippet to make it not go to the "do stuff"
    part!

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
    Bob Barrows [MVP], Jun 26, 2007
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ton 't Lam
    Replies:
    0
    Views:
    2,378
    Ton 't Lam
    Mar 10, 2006
  2. Remco Groot Beumer

    Variables are overwritten when another person logs in

    Remco Groot Beumer, Nov 5, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    325
    Mark Fitzpatrick
    Nov 5, 2003
  3. Showjumper

    Ensuring one vote per person

    Showjumper, Jul 17, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    444
    Ken Cox [Microsoft MVP]
    Jul 17, 2006
  4. flamesrock
    Replies:
    8
    Views:
    449
    Hendrik van Rooyen
    Nov 24, 2006
  5. Steve Bywaters

    ONE person gets an ASP error....

    Steve Bywaters, Dec 11, 2003, in forum: ASP General
    Replies:
    28
    Views:
    262
    Kris Eiben
    Dec 16, 2003
Loading...

Share This Page