NSession allows classic ASP Pages to access the ASP.NET State Service or SQL Server Session State.


Download the release from the download area. There are 2 DLLs to register. The first DLL, NSession.dll, is a .net framework 4.0 dll exposed as COM. While it can work in both the bit 32 and the 64 bit environments, the registration is different. To register it as 32 bit COM, from the command prompt, change to the directory where the dll is located and run:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm /tlb /codebase NSession.dll

To register it as 64 bit COM, run the following instead:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm /tlb /codebase NSession.dll

Adjust accordingly if your .net framework is at a different location. See this page for more information.

The NSession.dll is compiled using .NET framework 4. You need .NET framework 4 on the machine but you can run any version of ASP.NET as NSession.dll is not running in the same AppDomain as your ASP.NET application.

The second dll NSessionNative.dll is a C++ dll and is platform dependent. You need to register the appropriate version depending on whether you are running 32 or 64 bit application pool. Since it was compiled using Visual Studio 2013, you need to install Visual C++ Redistributable Packages for Visual Studio 2013

To register the 32 bit version in a 64 bit Windows, run:

C:\Windows\SysWOW64\regsvr32 PathToYour32BitNSessionNative.dll

To register the 64 bit version in a 64 bit Windows, run:

C:\Windows\system32\regsvr32 PathToYour32BitNSessionNative.dll

The reason that we need a C++ dll is that we need deterministic finalization. We chose C++ over VB6 because it can create both 32 bit and 64 bit COM objects.

The 32 bit and 64 bit registrations can co-exists because it simply writes to the 32 bit and 64 bit portion of the registry. It is recommended that you do both.


We don't break the COM compatibility. So you can just stop IIS to unload the DLLs and copy the new DLLs to the same location. No need to re-register. However, if there is any change in the ASP.NET part the Usage below, you still need to follow it.


ASP Classic

You need to instantiate one of the COM objects in your ASP classic page before it accesses session state, either:

set oSession = Server.CreateObject("NSession.Session")


set oSession = Server.CreateObject("NSession.ReadOnlySession")

If you instantiate NSession.Session, the session state in the session store will be transferred to the ASP Classic session dictionary, and an exclusive lock will be placed in the session store. You do not need to change your existing code that accesses the ASP Classic session object. When NSession.Session goes out of scope, it will save the ASP Classic session dictionary back to the session store and release the exclusive lock.

If you have done with the session state, you can release the lock early with

set oSession = Nothing

If you instantiate NSession.ReadOnlySession, the session state in the session store will be transferred to the ASP Classic session dictionary but no locks will be placed.


Note that in your application you must always let users access an asp.net page first to create a session cookie.

ASP.NET Session State
If you are using ASP.NET session state service, we need a little bit help from you to set the computed UriBase in a process environment variables. There are two ways to do it. The first way is run the diagnostic page in your application and follow the instructions to copy 1 line of code into your ApplicationStart. The second way is to always calculate the UriBase dynamically. In your global.asax, add the following code to your SessionStart handler:

    protected void Session_Start(object sender, EventArgs e)
        string appDomainAppId = HttpRuntime.AppDomainAppId;
        string uriBaseKey = string.Format("{0}_OUTOFPROCSESSIONSTATESTORE_URIBASE", appDomainAppId);
        string uribase = Environment.GetEnvironmentVariable(uriBaseKey, EnvironmentVariableTarget.Process);

        if (string.IsNullOrEmpty(uribase))
            foreach (string moduleName in this.Modules)
                IHttpModule module = this.Modules[moduleName];
                SessionStateModule ssm = module as SessionStateModule;
                if (ssm != null)
                    FieldInfo storeInfo = typeof(SessionStateModule).GetField("_store", BindingFlags.Instance | BindingFlags.NonPublic);
                    SessionStateStoreProviderBase store = (SessionStateStoreProviderBase)storeInfo.GetValue(ssm);
                    Type storeType = store.GetType();
                    if (storeType.Name.Equals("OutOfProcSessionStateStore"))
                        FieldInfo uribaseInfo = storeType.GetField("s_uribase", BindingFlags.Static | BindingFlags.NonPublic);
                        uribase = (string)uribaseInfo.GetValue(null);
                        Environment.SetEnvironmentVariable(uriBaseKey, uribase, 

This will add the session url to the process environment variable.

SQL Server Session State
No additional helps needed.

You might download the source code to examine the sample web application.

See Also

Trouble Shooting
How it works
Release Notes
Road Map

Last edited Apr 30, 2015 at 5:57 AM by dotneteer, version 17


sushantvn Oct 6, 2016 at 2:20 PM 
Hi all,
What are prerequisites to run this NSession solution...?
because I am not able to build this solution ... It gives reference error.

please provide your inputs

martinrousev Apr 1, 2015 at 2:03 PM 
Addendum to my previous comment:
I used dependency walker to see if something is missing and it shows 9 missing assemblies among which dcomp.dll, mfplat.dll, wlanapi.dll and the rest start with "api-ms-win-core-" any help with that?

martinrousev Apr 1, 2015 at 7:46 AM 
This seems like a great project and exactly what I need but it desperately needs better documentation. I can't get it to work. What I did so far:
* Registered the .NET assembly with RegAsm
* Registered the .NET assembly with gacutil
* Retistered the x64 assembly with regsvr32
* When I tried "set oSession = Server.CreateObject("NSession.Session")" Microsoft VBScript runtime error '800a01ad' ActiveX component can't create object
* I listed all COM objects that are on the system and the only present one with reference to NSession was NSession.SessionStateClient
* Switched the code to create an object from this one but then it can't be enumerated like so: oSession("sessionVariable")

What have I missed?

dotneteer Oct 30, 2014 at 4:35 AM 
You should use gacutil and regasm to install NSession.dll. This is a .net assembly that needs to be exposed to COM.

Use regsvr32 to install NSessionNative.dll. This is a native COM object. It is not a .net assembly.

Hope this helps.

deepakkarma Oct 18, 2013 at 12:58 PM 
For line in asp page
<% set oSession = Server.CreateObject("NSession.Session")

Session("dktest")="hello session checking "
' Response.Write(Session("dktest")&"hhhhhhh")

I am getting following error

Active Server Pages error 'ASP 0241'

CreateObject Exception


The CreateObject of '(null)' caused exception C0000005.

ADODB.Connection error 'c0000005'

Operation is not allowed when the object is closed.

/CMT/admin.asp, line 16

jmm89 Apr 17, 2013 at 9:08 AM 
Hi all,

My computer is 32 bit, I downloaded the source code and have compiled.

I followed the steps of installation and registration .dll: regasm, gacutil, regsvr32 ..., I have also set the machine key in the web.config, but when run and load the page "Test.asp" from "Default.aspx" in the following line:

set o = Server.CreateObject ("NSession.Session")

I get the following error:

Active Server Pages error 'ASP 0241'

CreateObject Exception

/ Test.asp

The CreateObject method "(null)" E06D7363 exception occurred.

Server object error 'ASP 0177: e06d7363'

Server.CreateObject Failed

/ Test.asp, line 8


Any idea what I'm doing wrong? Perhaps I lack any record of .Dll?

cooperba3 Oct 6, 2012 at 12:09 AM 
When trying to create the NSession COM component, I am getting the following error:
The call to Server.CreateObject failed while checking permissions. Access is denied to this object.
I have tried to add the Everyone user to be able to activate COM components, but that didn't work. Any ideas?

dtakamine Mar 14, 2012 at 11:01 PM 
I had the same issue and found the following to work fine for my 32 bit machine.:

"C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe" nsession.dll
"C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\gacutil.exe" /i nsession.dll
regsvr32 x86\NSessionNative.dll

miramardesign Jan 12, 2012 at 6:08 PM 

I cannot install NSessionNative.dll in the gac via drag-n-drop or gacutil.exe

error below-----------====================

C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin>gacutil /i NSessionNative.dll
Microsoft (R) .NET Global Assembly Cache Utility. Version 3.5.30729.1
Copyright (c) Microsoft Corporation. All rights reserved.

Failure adding assembly to the cache: The module was expected to contain an as
sembly manifest.