In. net, session storage is different from ASP storage. Although ASP and aspx can be run simultaneously under the same IIS, session cannot be transferred between them.
Previously, a large number of systems were applied to ASP. During the upgrade process, if ASP was completely discarded for rewriting, the workload would be too large, and the previous results would not be saved.
Therefore, Microsoft proposed a session sharing solution, but this document illustrates the principle and does not describe the specific operation steps. Therefore, I wrote an article to describe the process.
A brief description of the principle. sessions between ASP and Asp.net are stored in the database for sharing.
1. Create a data table
Open the 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 file session.rar
After the files are decompressed, four files are generated and the following operations are performed respectively.
Copy global. ASA to the root directory of the system, open the file, modify application ("sessiondsn") as the appropriate database link string, if the system already has global. 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 Web. config file of the system, add this item
<Add key = "sessiondsn" value = "Data Source = sqlservername; initial catalog = sessiondemodb; persist Security info = false; user id = sessiondemodbuser; Password = ****; packet size = 4096 "type =" codeph "text ="/codeph "/>
And change the value to the appropriate database link.
Copy the other two DLL files to the system directory (or another suitable directory)
3. Disable ASP session in IIS
Open IIS, select a site, and choose Properties> Home directory> Configuration> ApplicationProgramOption to remove the check box before the session status is enabled. For example:
Screen. Width-350) This. width = screen. Width-350 "border = 0>
4. Install sessionutility. dll
Find the gacutil.exe file, which is usually in the Microsoft Visual Studio. NET 2003 \ SDK \ V1.1 \ bin directory.
In the Command Prompt window, run gacutil/I sessionutility. dll. (If the execution fails, complete the paths of these two files)
5. Register sessionutility. dll as a COM object.
Similarly, find the regasm.exe file, which is usually in the WINNT \ Microsoft. NET \ framework \ v1.1.4322 directory.
In the Command Prompt window, run regasm.exe sessionutility. dll/TLB: sessionutility. TLB. (If the execution fails, complete the paths of the two files)
In this way, a TLB file is generated and can be called as a common COM component.
6. Register sessionmanager. dll
In the Command Prompt window, run regsvr32 sessionmanager. dll.
7. If it is an NTFS system, find sessionmgr. dll, right-click, properties, and set IUSR _ <machine_name> permission to readable and executable.
So far, we have achieved session sharing between ASP and Asp.net. How can we use it?
In ASP, we need to use the following:
Page start
Dim session
Set session = server. Createobject ("sessionmgr. session2 ")
Session ("userid") =...
...
...
...
Page end
Set session = nothing. Remember to release it.
In Asp.net, we need to use the following:
First, we need to add a reference to sessionutility.
Then, during the encoding, the public class webform1: system. Web. UI. Page is inherited and changed to public class webform1: msdn. sessionpage.
In this way, Session ("userid") can be used in the encoding process.
Note: Although the session is shared, the syntax of the session is relative. the newly added part of net is not implemented. After all, you need to take care of ASP
such as session. remove.