I forgot, help please

Discussion in 'ASP General' started by p byers, Jan 19, 2008.

  1. p byers

    p byers Guest

    Hi Folks

    I have seen a method of obtaining all of the SESSION (or COOKIES maybe)
    using a "for each" statement.

    BUT

    I have forgotten how/when/where I saw it.


    I am particularly interested in the "automatically generated long
    unique string Session Identifier"


    Please forgive my "No-Tech" description of what I require - I fear
    Senile Decay is happening quicker than I thought.

    Best regards
    Thank you
    Pete (Northolt UK)
     
    p byers, Jan 19, 2008
    #1
    1. Advertising

  2. p byers

    p byers Guest

    Should have said "Using ASP on the Server"

    p byers wrote:

    > Hi Folks
    >
    > I have seen a method of obtaining all of the SESSION (or COOKIES maybe)
    > using a "for each" statement.
    >
    > BUT
    >
    > I have forgotten how/when/where I saw it.
    >
    > I am particularly interested in the "automatically generated long
    > unique string Session Identifier"
    >
    > Please forgive my "No-Tech" description of what I require - I fear
    > Senile Decay is happening quicker than I thought.
    >
    > Best regards
    > Thank you
    > Pete (Northolt UK)
     
    p byers, Jan 19, 2008
    #2
    1. Advertising

  3. About half way down.
    http://www.angelfire.com/tx4/cus/notes/asp.html

    I add this one, as I like the way he has formatted his code. It is very easy
    to read and understand.

    --
    Gregory A. Beamer
    MVP, MCP: +I, SE, SD, DBA

    *************************************************
    | Think outside the box!
    |
    *************************************************
    "p byers" <> wrote in message
    news:...
    > Hi Folks
    >
    > I have seen a method of obtaining all of the SESSION (or COOKIES maybe)
    > using a "for each" statement.
    >
    > BUT
    >
    > I have forgotten how/when/where I saw it.
    >
    >
    > I am particularly interested in the "automatically generated long
    > unique string Session Identifier"
    >
    >
    > Please forgive my "No-Tech" description of what I require - I fear
    > Senile Decay is happening quicker than I thought.
    >
    > Best regards
    > Thank you
    > Pete (Northolt UK)
    >
    >
    >
     
    Cowboy \(Gregory A. Beamer\), Jan 19, 2008
    #3
  4. "Jon Paal [MSMD]" <Jon nospam Paal @ everywhere dot com> wrote in message
    news:...
    > google is your friend....
    >
    > <%
    > 'Print out the entire cookie collection.
    > '-----------------------------------------
    > For Each cookie in Request.Cookies
    > If Not cookie.HasKeys Then
    > 'Print out the cookie string
    > %>
    > <%= cookie %> = <%= Request.Cookies(cookie)%>
    > <%
    > Else
    > 'Print out the cookie collection
    > '------------------------------------------
    > For Each key in Request.Cookies(cookie)
    > %>
    > <%= cookie %> (<%= key %>) = <%= Request.Cookies(cookie)(key)%>
    > <%
    > Next
    > End If
    > Next
    > %>
    >


    Close but no banana. ;)

    Try:-

    Dim cookie, key, subKey
    Dim i
    'Print out the entire cookie collection.
    '-----------------------------------------
    For Each key in Request.Cookies
    Set cookie = Request.Cookies(key)
    If Not cookie.HasKeys Then
    'Print out the cookie string
    %>
    <%=key %> = <%=cookie%><br />
    <%
    Else
    'Print out the cookie collection
    '------------------------------------------
    For Each subKey in cookie
    %>
    <%= key %> (<%= subKey %>) = <%= cookie(subKey)%><br />
    <%
    Next
    End If
    Next


    --
    Anthony Jones - MVP ASP/ASP.NET
     
    Anthony Jones, Jan 19, 2008
    #4
  5. p byers

    p byers Guest

    Thank you both for you quick helpful replies
    Pete (Northolt UK)

    p byers wrote:

    > Hi Folks
    >
    > I have seen a method of obtaining all of the SESSION (or COOKIES maybe)
    > using a "for each" statement.
    >
    > BUT
    >
    > I have forgotten how/when/where I saw it.
    >
    > I am particularly interested in the "automatically generated long
    > unique string Session Identifier"
    >
    > Please forgive my "No-Tech" description of what I require - I fear
    > Senile Decay is happening quicker than I thought.
    >
    > Best regards
    > Thank you
    > Pete (Northolt UK)
     
    p byers, Jan 19, 2008
    #5
  6. "p byers" <> wrote in message
    news:...
    > Hi Folks
    >
    > I have seen a method of obtaining all of the SESSION (or COOKIES maybe)
    > using a "for each" statement.
    >
    > BUT
    >
    > I have forgotten how/when/where I saw it.
    >
    >
    > I am particularly interested in the "automatically generated long
    > unique string Session Identifier"
    >
    >
    > Please forgive my "No-Tech" description of what I require - I fear
    > Senile Decay is happening quicker than I thought.
    >



    If you run the code posted elsewhere in this thread you'll get list of the
    current cookies in the request. You'll notice though that the one cookie
    that you're actually after is missing. It is consumed by ASP in order to
    included the correct session object in the script context and is not made
    available in the Request.Cookies collection.

    You can see it thougn in this:-

    Response.Write Request.ServerVariables("HTTP_COOKIE")

    But this is simplye the cookie header value in full so will contain all
    cookies for the currently location unparsedd.


    You could extract it with some Regex:-

    Dim sCookieHeader : sCookieHeader = Request.ServerVariables("HTTP_COOKIE")
    Dim rgx : Set rgx = NewRegExp("ASPSESSIONID([A-Z0-9]+)=([A-Z0-9]+)", True,
    True)
    Dim oMatch
    For Each oMatch in rgx.Execute(sCookieHeader)
    Response.Write oMatch.Value & "<br />"
    Response.Write "App Instance: " & oMatch.SubMatches(0) & "<br />"
    Response.Write "Session Code: " & oMatch.SubMatches(1) & "<br />"
    Next

    Function NewRegExp(rsPattern, rbGlobal, rbCaseInsensitive)

    Set NewRegExp = new RegExp
    NewRegExp.Pattern = rsPattern
    NewRegExp.Global = rbGlobal
    NewRegExp.IgnoreCase = rbCaseInsensitive

    End Function


    However if you were to unload the app or recycle the app pool you will start
    to see multiple ASPSESSIONIDxxxxx headers. I guess you will need to know
    which is the current one, its guess because I'm not sure how any of this
    would be useful?



    --
    Anthony Jones - MVP ASP/ASP.NET
     
    Anthony Jones, Jan 19, 2008
    #6
  7. Anthony wrote on Sat, 19 Jan 2008 22:23:58 -0000:

    > "p byers" <> wrote in message
    > news:...
    >> Hi Folks


    >> I have seen a method of obtaining all of the SESSION (or COOKIES
    >> maybe)
    >> using a "for each" statement.


    >> BUT


    >> I have forgotten how/when/where I saw it.



    >> I am particularly interested in the "automatically generated long
    >> unique string Session Identifier"



    >> Please forgive my "No-Tech" description of what I require - I fear
    >> Senile Decay is happening quicker than I thought.




    > If you run the code posted elsewhere in this thread you'll get list of
    > the current cookies in the request. You'll notice though that the one
    > cookie that you're actually after is missing. It is consumed by ASP in
    > order to included the correct session object in the script context and
    > is not made available in the Request.Cookies collection.


    > You can see it thougn in this:-


    > Response.Write Request.ServerVariables("HTTP_COOKIE")


    > But this is simplye the cookie header value in full so will contain all
    > cookies for the currently location unparsedd.



    > You could extract it with some Regex:-


    > Dim sCookieHeader : sCookieHeader =
    > Request.ServerVariables("HTTP_COOKIE")
    > Dim rgx : Set rgx = NewRegExp("ASPSESSIONID([A-Z0-9]+)=([A-Z0-9]+)",
    > True,
    > True)
    > Dim oMatch
    > For Each oMatch in rgx.Execute(sCookieHeader)
    > Response.Write oMatch.Value & "<br />"
    > Response.Write "App Instance: " & oMatch.SubMatches(0) & "<br />"
    > Response.Write "Session Code: " & oMatch.SubMatches(1) & "<br />"
    > Next


    > Function NewRegExp(rsPattern, rbGlobal, rbCaseInsensitive)


    > Set NewRegExp = new RegExp
    > NewRegExp.Pattern = rsPattern
    > NewRegExp.Global = rbGlobal
    > NewRegExp.IgnoreCase = rbCaseInsensitive


    > End Function



    > However if you were to unload the app or recycle the app pool you will
    > start to see multiple ASPSESSIONIDxxxxx headers. I guess you will
    > need to know which is the current one, its guess because I'm not sure
    > how any of this would be useful?



    Doesn't

    Response.Write Session.SessionID

    return the appropriate session ID value that is currently in use (assuming
    that sessions are enabled of course).

    --
    Dan
     
    Daniel Crichton, Jan 21, 2008
    #7
  8. Daniel wrote to Anthony Jones on Mon, 21 Jan 2008 13:38:05 -0000:

    > Anthony wrote on Sat, 19 Jan 2008 22:23:58 -0000:


    >> "p byers" <> wrote in message
    >> news:...
    >>> Hi Folks


    >>> I have seen a method of obtaining all of the SESSION (or COOKIES
    >>> maybe)
    >>> using a "for each" statement.


    >>> BUT


    >>> I have forgotten how/when/where I saw it.



    >>> I am particularly interested in the "automatically generated long
    >>> unique string Session Identifier"



    >>> Please forgive my "No-Tech" description of what I require - I fear
    >>> Senile Decay is happening quicker than I thought.




    >> If you run the code posted elsewhere in this thread you'll get list
    >> of the current cookies in the request. You'll notice though that the
    >> one cookie that you're actually after is missing. It is consumed by
    >> ASP in order to included the correct session object in the script
    >> context and is not made available in the Request.Cookies collection.


    >> You can see it thougn in this:-


    >> Response.Write Request.ServerVariables("HTTP_COOKIE")


    >> But this is simplye the cookie header value in full so will contain
    >> all cookies for the currently location unparsedd.



    >> You could extract it with some Regex:-


    >> Dim sCookieHeader : sCookieHeader =
    >> Request.ServerVariables("HTTP_COOKIE")
    >> Dim rgx : Set rgx = NewRegExp("ASPSESSIONID([A-Z0-9]+)=([A-Z0-9]+)",
    >> True,
    >> True)
    >> Dim oMatch
    >> For Each oMatch in rgx.Execute(sCookieHeader)
    >> Response.Write oMatch.Value & "<br />"
    >> Response.Write "App Instance: " & oMatch.SubMatches(0) & "<br />"
    >> Response.Write "Session Code: " & oMatch.SubMatches(1) & "<br />"
    >> Next


    >> Function NewRegExp(rsPattern, rbGlobal, rbCaseInsensitive)


    >> Set NewRegExp = new RegExp
    >> NewRegExp.Pattern = rsPattern
    >> NewRegExp.Global = rbGlobal
    >> NewRegExp.IgnoreCase = rbCaseInsensitive


    >> End Function



    >> However if you were to unload the app or recycle the app pool you
    >> will start to see multiple ASPSESSIONIDxxxxx headers. I guess you
    >> will need to know which is the current one, its guess because I'm not
    >> sure how any of this would be useful?



    > Doesn't


    > Response.Write Session.SessionID


    > return the appropriate session ID value that is currently in use
    > (assuming that sessions are enabled of course).


    Sorry for not posting a complete reply.

    Anyway, once you've got the value of Session.SessionID, you should then be
    able to compare it's value to the ASPSESSIONIDxxxxx values and find the
    correct one, assuming that you don't have two with the same value (which
    shouldn't happen normally, but there's always a chance).

    --
    Dan
     
    Daniel Crichton, Jan 21, 2008
    #8
  9. "Daniel Crichton" <> wrote in message
    news:...
    > Daniel wrote to Anthony Jones on Mon, 21 Jan 2008 13:38:05 -0000:
    >
    > > Anthony wrote on Sat, 19 Jan 2008 22:23:58 -0000:

    >
    > >> "p byers" <> wrote in message
    > >> news:...
    > >>> Hi Folks

    >
    > >>> I have seen a method of obtaining all of the SESSION (or COOKIES
    > >>> maybe)
    > >>> using a "for each" statement.

    >
    > >>> BUT

    >
    > >>> I have forgotten how/when/where I saw it.

    >
    >
    > >>> I am particularly interested in the "automatically generated long
    > >>> unique string Session Identifier"

    >
    >
    > >>> Please forgive my "No-Tech" description of what I require - I fear
    > >>> Senile Decay is happening quicker than I thought.

    >
    >
    >
    > >> If you run the code posted elsewhere in this thread you'll get list
    > >> of the current cookies in the request. You'll notice though that the
    > >> one cookie that you're actually after is missing. It is consumed by
    > >> ASP in order to included the correct session object in the script
    > >> context and is not made available in the Request.Cookies collection.

    >
    > >> You can see it thougn in this:-

    >
    > >> Response.Write Request.ServerVariables("HTTP_COOKIE")

    >
    > >> But this is simplye the cookie header value in full so will contain
    > >> all cookies for the currently location unparsedd.

    >
    >
    > >> You could extract it with some Regex:-

    >
    > >> Dim sCookieHeader : sCookieHeader =
    > >> Request.ServerVariables("HTTP_COOKIE")
    > >> Dim rgx : Set rgx = NewRegExp("ASPSESSIONID([A-Z0-9]+)=([A-Z0-9]+)",
    > >> True,
    > >> True)
    > >> Dim oMatch
    > >> For Each oMatch in rgx.Execute(sCookieHeader)
    > >> Response.Write oMatch.Value & "<br />"
    > >> Response.Write "App Instance: " & oMatch.SubMatches(0) & "<br />"
    > >> Response.Write "Session Code: " & oMatch.SubMatches(1) & "<br />"
    > >> Next

    >
    > >> Function NewRegExp(rsPattern, rbGlobal, rbCaseInsensitive)

    >
    > >> Set NewRegExp = new RegExp
    > >> NewRegExp.Pattern = rsPattern
    > >> NewRegExp.Global = rbGlobal
    > >> NewRegExp.IgnoreCase = rbCaseInsensitive

    >
    > >> End Function

    >
    >
    > >> However if you were to unload the app or recycle the app pool you
    > >> will start to see multiple ASPSESSIONIDxxxxx headers. I guess you
    > >> will need to know which is the current one, its guess because I'm not
    > >> sure how any of this would be useful?

    >
    >
    > > Doesn't

    >
    > > Response.Write Session.SessionID

    >
    > > return the appropriate session ID value that is currently in use
    > > (assuming that sessions are enabled of course).

    >
    > Sorry for not posting a complete reply.
    >
    > Anyway, once you've got the value of Session.SessionID, you should then be
    > able to compare it's value to the ASPSESSIONIDxxxxx values and find the
    > correct one, assuming that you don't have two with the same value (which
    > shouldn't happen normally, but there's always a chance).
    >


    Its a good point. I was working on the assumption that SessionID is not
    useful for some reason. I didn't occur to me that the OP may not be aware of
    its existance.

    I'm not sure why there would be any need to compare it to the cookie value
    though. Also I'm not sure how or even if its possible to map the value of
    SessionID to the cooke value.

    --
    Anthony Jones - MVP ASP/ASP.NET
     
    Anthony Jones, Jan 21, 2008
    #9
  10. Anthony wrote on Mon, 21 Jan 2008 21:57:23 -0000:

    > "Daniel Crichton" <> wrote in message
    > news:...
    >> Daniel wrote to Anthony Jones on Mon, 21 Jan 2008 13:38:05 -0000:


    >>> Anthony wrote on Sat, 19 Jan 2008 22:23:58 -0000:


    >>>> "p byers" <> wrote in message
    >>>> news:...
    >>>>> Hi Folks


    >>>>> I have seen a method of obtaining all of the SESSION (or COOKIES
    >>>>> maybe)
    >>>>> using a "for each" statement.


    >>>>> BUT


    >>>>> I have forgotten how/when/where I saw it.



    >>>>> I am particularly interested in the "automatically generated long
    >>>>> unique string Session Identifier"



    >>>>> Please forgive my "No-Tech" description of what I require - I
    >>>>> fear
    >>>>> Senile Decay is happening quicker than I thought.




    >>>> If you run the code posted elsewhere in this thread you'll get list
    >>>> of the current cookies in the request. You'll notice though that
    >>>> the one cookie that you're actually after is missing. It is
    >>>> consumed by
    >>>> ASP in order to included the correct session object in the script
    >>>> context and is not made available in the Request.Cookies
    >>>> collection.


    >>>> You can see it thougn in this:-


    >>>> Response.Write Request.ServerVariables("HTTP_COOKIE")


    >>>> But this is simplye the cookie header value in full so will contain
    >>>> all cookies for the currently location unparsedd.



    >>>> You could extract it with some Regex:-


    >>>> Dim sCookieHeader : sCookieHeader =
    >>>> Request.ServerVariables("HTTP_COOKIE")
    >>>> Dim rgx : Set rgx =
    >>>> NewRegExp("ASPSESSIONID([A-Z0-9]+)=([A-Z0-9]+)",
    >>>> True,
    >>>> True)
    >>>> Dim oMatch
    >>>> For Each oMatch in rgx.Execute(sCookieHeader)
    >>>> Response.Write oMatch.Value & "<br />"
    >>>> Response.Write "App Instance: " & oMatch.SubMatches(0) & "<br />"
    >>>> Response.Write "Session Code: " & oMatch.SubMatches(1) & "<br />"
    >>>> Next


    >>>> Function NewRegExp(rsPattern, rbGlobal, rbCaseInsensitive)


    >>>> Set NewRegExp = new RegExp
    >>>> NewRegExp.Pattern = rsPattern
    >>>> NewRegExp.Global = rbGlobal
    >>>> NewRegExp.IgnoreCase = rbCaseInsensitive


    >>>> End Function



    >>>> However if you were to unload the app or recycle the app pool you
    >>>> will start to see multiple ASPSESSIONIDxxxxx headers. I guess you
    >>>> will need to know which is the current one, its guess because I'm
    >>>> not sure how any of this would be useful?



    >>> Doesn't


    >>> Response.Write Session.SessionID


    >>> return the appropriate session ID value that is currently in use
    >>> (assuming that sessions are enabled of course).


    >> Sorry for not posting a complete reply.


    >> Anyway, once you've got the value of Session.SessionID, you should
    >> then be able to compare it's value to the ASPSESSIONIDxxxxx values
    >> and find the correct one, assuming that you don't have two with the
    >> same value (which shouldn't happen normally, but there's always a
    >> chance).



    > Its a good point. I was working on the assumption that SessionID is not
    > useful for some reason. I didn't occur to me that the OP may not be
    > aware of its existance.


    > I'm not sure why there would be any need to compare it to the cookie
    > value though. Also I'm not sure how or even if its possible to map the
    > value of
    > SessionID to the cooke value.


    Given that you can parse the HTTP_COOKIE header, and so extract the values
    for each ASPSESSIONIDxxxxxx cookie, and using the value of .SessionID, you
    should then be able to find the ASPSESSIONIDxxxxxx cookie that is passing
    the SessionID. Whether this is useful to know or not is anyone's guess :p

    But at least there is a way of getting the "automatically generated long
    unique string Session Identifier" that the OP was asking for, which should
    be Session.SessionID.

    --
    Dan
     
    Daniel Crichton, Jan 22, 2008
    #10
  11. "Daniel Crichton" <> wrote in message
    news:...
    > Anthony wrote on Mon, 21 Jan 2008 21:57:23 -0000:
    >
    > > "Daniel Crichton" <> wrote in message
    > > news:...
    > >> Daniel wrote to Anthony Jones on Mon, 21 Jan 2008 13:38:05 -0000:

    >
    > >>> Anthony wrote on Sat, 19 Jan 2008 22:23:58 -0000:

    >
    > >>>> "p byers" <> wrote in message
    > >>>> news:...
    > >>>>> Hi Folks

    >
    > >>>>> I have seen a method of obtaining all of the SESSION (or COOKIES
    > >>>>> maybe)
    > >>>>> using a "for each" statement.

    >
    > >>>>> BUT

    >
    > >>>>> I have forgotten how/when/where I saw it.

    >
    >
    > >>>>> I am particularly interested in the "automatically generated long
    > >>>>> unique string Session Identifier"

    >
    >
    > >>>>> Please forgive my "No-Tech" description of what I require - I
    > >>>>> fear
    > >>>>> Senile Decay is happening quicker than I thought.

    >
    >
    >
    > >>>> If you run the code posted elsewhere in this thread you'll get list
    > >>>> of the current cookies in the request. You'll notice though that
    > >>>> the one cookie that you're actually after is missing. It is
    > >>>> consumed by
    > >>>> ASP in order to included the correct session object in the script
    > >>>> context and is not made available in the Request.Cookies
    > >>>> collection.

    >
    > >>>> You can see it thougn in this:-

    >
    > >>>> Response.Write Request.ServerVariables("HTTP_COOKIE")

    >
    > >>>> But this is simplye the cookie header value in full so will contain
    > >>>> all cookies for the currently location unparsedd.

    >
    >
    > >>>> You could extract it with some Regex:-

    >
    > >>>> Dim sCookieHeader : sCookieHeader =
    > >>>> Request.ServerVariables("HTTP_COOKIE")
    > >>>> Dim rgx : Set rgx =
    > >>>> NewRegExp("ASPSESSIONID([A-Z0-9]+)=([A-Z0-9]+)",
    > >>>> True,
    > >>>> True)
    > >>>> Dim oMatch
    > >>>> For Each oMatch in rgx.Execute(sCookieHeader)
    > >>>> Response.Write oMatch.Value & "<br />"
    > >>>> Response.Write "App Instance: " & oMatch.SubMatches(0) & "<br />"
    > >>>> Response.Write "Session Code: " & oMatch.SubMatches(1) & "<br />"
    > >>>> Next

    >
    > >>>> Function NewRegExp(rsPattern, rbGlobal, rbCaseInsensitive)

    >
    > >>>> Set NewRegExp = new RegExp
    > >>>> NewRegExp.Pattern = rsPattern
    > >>>> NewRegExp.Global = rbGlobal
    > >>>> NewRegExp.IgnoreCase = rbCaseInsensitive

    >
    > >>>> End Function

    >
    >
    > >>>> However if you were to unload the app or recycle the app pool you
    > >>>> will start to see multiple ASPSESSIONIDxxxxx headers. I guess you
    > >>>> will need to know which is the current one, its guess because I'm
    > >>>> not sure how any of this would be useful?

    >
    >
    > >>> Doesn't

    >
    > >>> Response.Write Session.SessionID

    >
    > >>> return the appropriate session ID value that is currently in use
    > >>> (assuming that sessions are enabled of course).

    >
    > >> Sorry for not posting a complete reply.

    >
    > >> Anyway, once you've got the value of Session.SessionID, you should
    > >> then be able to compare it's value to the ASPSESSIONIDxxxxx values
    > >> and find the correct one, assuming that you don't have two with the
    > >> same value (which shouldn't happen normally, but there's always a
    > >> chance).

    >
    >
    > > Its a good point. I was working on the assumption that SessionID is not
    > > useful for some reason. I didn't occur to me that the OP may not be
    > > aware of its existance.

    >
    > > I'm not sure why there would be any need to compare it to the cookie
    > > value though. Also I'm not sure how or even if its possible to map the
    > > value of
    > > SessionID to the cooke value.

    >
    > Given that you can parse the HTTP_COOKIE header, and so extract the values
    > for each ASPSESSIONIDxxxxxx cookie, and using the value of .SessionID, you
    > should then be able to find the ASPSESSIONIDxxxxxx cookie that is passing
    > the SessionID. Whether this is useful to know or not is anyone's guess :p
    >
    > But at least there is a way of getting the "automatically generated long
    > unique string Session Identifier" that the OP was asking for, which should
    > be Session.SessionID.


    Ah but is it though? That's the point I'm trying to make. Perhaps a sample
    will make it clear:-

    Session ID: <%=Session.SessionID%><br />
    <br />
    <%
    Dim sCookieHeader : sCookieHeader = Request.ServerVariables("HTTP_COOKIE")
    Dim oMatch
    For Each oMatch in NewRegExp("ASPSESSIONID([A-Z0-9]+)=([A-Z0-9]+)", True,
    True).Execute(sCookieHeader)
    Response.Write oMatch.Value & "<br />"
    Response.Write "App Instance: " & oMatch.SubMatches(0) & "<br />"
    Response.Write "Session Code: " & oMatch.SubMatches(1) & "<br />"
    Next

    Function NewRegExp(rsPattern, rbGlobal, rbCaseInsensitive)

    Set NewRegExp = new RegExp
    NewRegExp.Pattern = rsPattern
    NewRegExp.Global = rbGlobal
    NewRegExp.IgnoreCase = rbCaseInsensitive

    End Function
    %>

    Hit a page with this code in and refresh it for good measure. Then go into
    IIS manager and recycle the app pool (or unload the app from the home
    directory tab if using 5.1 or below).

    Now referesh the page a couple more times. You'll note that you end up with
    two ASPSESSIONIDxxxxxxx cookies. For example I end up with:-

    Session ID: 771969469

    ASPSESSIONIDSSTDDBCA=LMAPAAOCHCCELDPEKPDAOECH
    App Instance: SSTDDBCA
    Session Code: LMAPAAOCHCCELDPEKPDAOECH
    ASPSESSIONIDSQTABCDA=NLBFDAOCKCODENCGMBCCMIHH
    App Instance: SQTABCDA
    Session Code: NLBFDAOCKCODENCGMBCCMIHH

    So the big question is how do I determine which of LMAPAAOCHCCELDPEKPDAOECH
    or NLBFDAOCKCODENCGMBCCMIHH is equivalent to 771969469?

    It is not apparent to me how these can be reconciled.

    --
    Anthony Jones - MVP ASP/ASP.NET
     
    Anthony Jones, Jan 22, 2008
    #11
  12. Anthony wrote on Tue, 22 Jan 2008 10:17:17 -0000:

    > "Daniel Crichton" <> wrote in message
    > news:...
    >> Anthony wrote on Mon, 21 Jan 2008 21:57:23 -0000:


    >>> "Daniel Crichton" <> wrote in message
    >>> news:...
    >>>> Daniel wrote to Anthony Jones on Mon, 21 Jan 2008 13:38:05 -0000:


    >>>>> Anthony wrote on Sat, 19 Jan 2008 22:23:58 -0000:


    >>>>>> "p byers" <> wrote in message
    >>>>>> news:...
    >>>>>>> Hi Folks


    >>>>>>> I have seen a method of obtaining all of the SESSION (or
    >>>>>>> COOKIES maybe)
    >>>>>>> using a "for each" statement.


    >>>>>>> BUT


    >>>>>>> I have forgotten how/when/where I saw it.



    >>>>>>> I am particularly interested in the "automatically generated
    >>>>>>> long unique string Session Identifier"



    >>>>>>> Please forgive my "No-Tech" description of what I require - I
    >>>>>>> fear
    >>>>>>> Senile Decay is happening quicker than I thought.




    >>>>>> If you run the code posted elsewhere in this thread you'll get
    >>>>>> list of the current cookies in the request. You'll notice though
    >>>>>> that the one cookie that you're actually after is missing. It is
    >>>>>> consumed by
    >>>>>> ASP in order to included the correct session object in the script
    >>>>>> context and is not made available in the Request.Cookies
    >>>>>> collection.


    >>>>>> You can see it thougn in this:-


    >>>>>> Response.Write Request.ServerVariables("HTTP_COOKIE")


    >>>>>> But this is simplye the cookie header value in full so will
    >>>>>> contain all cookies for the currently location unparsedd.



    >>>>>> You could extract it with some Regex:-


    >>>>>> Dim sCookieHeader : sCookieHeader =
    >>>>>> Request.ServerVariables("HTTP_COOKIE")
    >>>>>> Dim rgx : Set rgx =
    >>>>>> NewRegExp("ASPSESSIONID([A-Z0-9]+)=([A-Z0-9]+)",
    >>>>>> True,
    >>>>>> True)
    >>>>>> Dim oMatch
    >>>>>> For Each oMatch in rgx.Execute(sCookieHeader)
    >>>>>> Response.Write oMatch.Value & "<br />"
    >>>>>> Response.Write "App Instance: " & oMatch.SubMatches(0) & "<br
    >>>>>> />"
    >>>>>> Response.Write "Session Code: " & oMatch.SubMatches(1) & "<br
    >>>>>> />"
    >>>>>> Next


    >>>>>> Function NewRegExp(rsPattern, rbGlobal, rbCaseInsensitive)


    >>>>>> Set NewRegExp = new RegExp
    >>>>>> NewRegExp.Pattern = rsPattern
    >>>>>> NewRegExp.Global = rbGlobal
    >>>>>> NewRegExp.IgnoreCase = rbCaseInsensitive


    >>>>>> End Function



    >>>>>> However if you were to unload the app or recycle the app pool you
    >>>>>> will start to see multiple ASPSESSIONIDxxxxx headers. I guess
    >>>>>> you will need to know which is the current one, its guess because
    >>>>>> I'm not sure how any of this would be useful?



    >>>>> Doesn't


    >>>>> Response.Write Session.SessionID


    >>>>> return the appropriate session ID value that is currently in use
    >>>>> (assuming that sessions are enabled of course).


    >>>> Sorry for not posting a complete reply.


    >>>> Anyway, once you've got the value of Session.SessionID, you should
    >>>> then be able to compare it's value to the ASPSESSIONIDxxxxx values
    >>>> and find the correct one, assuming that you don't have two with the
    >>>> same value (which shouldn't happen normally, but there's always a
    >>>> chance).



    >>> Its a good point. I was working on the assumption that SessionID is
    >>> not useful for some reason. I didn't occur to me that the OP may not
    >>> be aware of its existance.


    >>> I'm not sure why there would be any need to compare it to the cookie
    >>> value though. Also I'm not sure how or even if its possible to map
    >>> the value of
    >>> SessionID to the cooke value.


    >> Given that you can parse the HTTP_COOKIE header, and so extract the
    >> values for each ASPSESSIONIDxxxxxx cookie, and using the value of
    >> .SessionID, you should then be able to find the ASPSESSIONIDxxxxxx
    >> cookie that is passing the SessionID. Whether this is useful to know
    >> or not is anyone's guess :p


    >> But at least there is a way of getting the "automatically generated
    >> long unique string Session Identifier" that the OP was asking for,
    >> which should be Session.SessionID.


    > Ah but is it though? That's the point I'm trying to make. Perhaps a
    > sample will make it clear:-


    > Session ID: <%=Session.SessionID%><br />
    > <br />
    > <%
    > Dim sCookieHeader : sCookieHeader =
    > Request.ServerVariables("HTTP_COOKIE")
    > Dim oMatch
    > For Each oMatch in NewRegExp("ASPSESSIONID([A-Z0-9]+)=([A-Z0-9]+)",
    > True,
    > True).Execute(sCookieHeader)
    > Response.Write oMatch.Value & "<br />"
    > Response.Write "App Instance: " & oMatch.SubMatches(0) & "<br />"
    > Response.Write "Session Code: " & oMatch.SubMatches(1) & "<br />"
    > Next


    > Function NewRegExp(rsPattern, rbGlobal, rbCaseInsensitive)


    > Set NewRegExp = new RegExp
    > NewRegExp.Pattern = rsPattern
    > NewRegExp.Global = rbGlobal
    > NewRegExp.IgnoreCase = rbCaseInsensitive


    > End Function %>


    > Hit a page with this code in and refresh it for good measure. Then go
    > into
    > IIS manager and recycle the app pool (or unload the app from the home
    > directory tab if using 5.1 or below).


    > Now referesh the page a couple more times. You'll note that you end up
    > with two ASPSESSIONIDxxxxxxx cookies. For example I end up with:-


    > Session ID: 771969469


    > ASPSESSIONIDSSTDDBCA=LMAPAAOCHCCELDPEKPDAOECH
    > App Instance: SSTDDBCA
    > Session Code: LMAPAAOCHCCELDPEKPDAOECH
    > ASPSESSIONIDSQTABCDA=NLBFDAOCKCODENCGMBCCMIHH
    > App Instance: SQTABCDA
    > Session Code: NLBFDAOCKCODENCGMBCCMIHH


    > So the big question is how do I determine which of
    > LMAPAAOCHCCELDPEKPDAOECH or NLBFDAOCKCODENCGMBCCMIHH is equivalent
    > to 771969469?


    > It is not apparent to me how these can be reconciled.


    In that case just call me an idiot - I had assumed (obviously incorrectly)
    that the SessionID value matched the current cookie value. Next time I'll
    actually test my assumption before posting, I normally would have but I've
    had my head dug in ASP for the past few weeks for a new web site we just
    launched.

    --
    Dan
     
    Daniel Crichton, Jan 23, 2008
    #12
    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. Joe777

    I forgot to mention...

    Joe777, May 6, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    348
    Joe Van Meer
    May 6, 2004
  2. mglover

    forgot to mention

    mglover, Jul 22, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    838
    Bobby Ryzhy
    Jul 22, 2004
  3. Shapper
    Replies:
    2
    Views:
    335
    Shapper
    Oct 12, 2005
  4. Replies:
    0
    Views:
    1,007
  5. KK
    Replies:
    2
    Views:
    664
    Big Brian
    Oct 14, 2003
Loading...

Share This Page