The NSession.dll wraps OutOfProcSessionStateStore, the same class used by ASP.NET to connect to the Session State Server. According to the Session State Provider document, a session provider has several important methods:
  1. GetItem: Get the session from session store into the memory. Do not lock the store.
  2. GetItemExclusive: Get the session into memory and lock the store so that the page can write the session state later. The session store MUST BE unlocked.
  3. SetAndReleaseItemExclusive: Persist the session and unlock the store.

Technically, an asp classic page can use managed NSession.dll directly, as in the TestManaged.asp page:

<%
    dim o

    set o = Server.CreateObject("NSession.SessionStateClient")
    o.GetItemExclusive() 'Get items and lock sesison for write
    'o.GetItems() 'Get items without locking the session. Things you write to session will not propagate. No need to call SetAndReleaseItemExclusive.
    Response.Write "The secret is "
    Response.Write Session("MyVar")
    Session("MyVar2") = "This is the secret saved by the asp classic page."
    o.SetAndReleaseItemExclusive() 'Unlock session
 %>


In an error occur and the code does not reach SetAndReleaseItemExclusive, the stored would be locked forever. That is why we implemented a Native wrapper with deterministic finalization to guarantee that the session store would be unlocked.

A tricky place is that different version of ASP.NET uses different URL to connect to the state service. In the latest version, we relying on the code in Session_Start to tell ASP Classic the url used to connect to the state service.

Last edited Apr 5, 2015 at 10:03 PM by dotneteer, version 1

Comments

No comments yet.