SoFunction
Updated on 2025-03-04

Methods to implement Asp and Shared Session

<iframe align="top" marginwidth="0" marginheight="0" src="/" frameborder="0" width="468" scrolling="no" height="60"></iframe>

In .net, the storage mechanism of Session is different from that of Asp. Although it can run asp and aspx at the same time under the same IIS, Session cannot be passed between them.
Previously, a large number of systems were used to asp. During the upgrade process, if the asp is completely abandoned and rewrite it, the workload is too large, and the previous results cannot be preserved.
So Microsoft proposed a Session sharing solution, but this document only explains the principle and does not mention the specific operation steps. Therefore, I wrote an article to describe the process.

Briefly explain the principle, the session between asp is stored in the database to realize sharing

1. Create a data table
Open SQL Server Query Analyzer and run the following script to create a data table named SessionState

if exists (select * from sysobjects where id = object_id(N'[dbo].[SessionState]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) 
drop table [dbo].[SessionState] 
GO 

create TABLE [dbo].[SessionState] ( 
[ID] uniqueidentifier NOT NULL , 
[Data] [image] NOT NULL , 
[Last_Accessed] [datetime] NOT NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] 
GO 

alter TABLE [dbo].[SessionState] WITH NOCHECK ADD 
CONSTRAINT [PK_SessionState] PRIMARY KEY NONCLUSTERED 
( 
[ID] 
) ON [PRIMARY] 
GO

2. Download the following files

After decompressing the file, 4 files will be generated, and the following operations will be performed.
Copy to the system root directory, open the file, modify Application ("SessionDSN") to the appropriate database link string. If the system itself already has it, add the following Application to this file:
Application("SessionDSN") = "initial catalog=SqlServerName;persist security info=False;user id=sa;password=****;packet size=4096"
In the system file, add this item
<add key="SessionDSN" value="data source=SqlServerName;initial catalog=SessionDemoDb;persist security info=False;user id=SessionDemoDbUser;password=****;packet size=4096"></add>
and modify its value to the appropriate database link.
Copy the other two dll files to the system directory (or other suitable directory)

3. Turn off the Session option of Asp in IIS
Open IIS, select site, and then select Properties -> Home Directory -> Configuration -> Application Options to remove the check mark before enabling session status. As shown in the figure below:
-350)=-350" border=0>

4. Installation
First find the file, usually in the Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin directory
In the command prompt window, execute gacutil /i (if the execution fails, please write all the paths of both files)

5. Register as a Com object
Similarly, to find the file, usually in the WINNT\\Framework\v1.1.4322 directory
In the command prompt window, execute /tlb: (If the execution fails, please write all the paths of these two files)
This will generate a tlb file, which can be called as an ordinary Com component.

6. Register
This is very simple. In the command prompt window, execute regsvr32

7. If it is a system in NTFS format, please find , right-click, and property to set the IUSR_<machine_name> permission to be readable and executable. At this point, we can already implement the Session sharing between Asp, so how to use it. In Asp, we need to use it as follows: <br>Dim Session <br>Set Session = ("SessionMgr.Session2") <br>Session("UserID") = ... <br>... <br>... <br>... <br>End of Page <br>Set Session = Nothing 'Remember to release it, and in, we need to use it as follows: <br>First, we need to add a reference to SessionUtility <br>Then, when encoding, it turns out that this is the inheritance of public class WebForm1 : , and modify it to public class WebForm1 : <br>In this way, the form of Session ("UserID") can be used during the encoding process. Note: Although Session implements sharing, the use syntax of Session is not implemented compared to the newly added parts in .net. After all, you have to take care of asp <br>For example, it cannot be used. <p >Trackback: /?PostId=1621435</p> <br></machine_name>