Asp and Asp.Net share Session methods

  • 2021-01-19 22:13:07
  • OfStack


<iframe align="top" marginwidth="0" marginheight="0" src="http://www.zealware.com/46860.html" frameborder="0" width="468" scrolling="no" height="60"></iframe>

In.net, the storage mechanism of Session is no longer the same as that of Asp, although it is possible to run asp and aspx simultaneously under the same IIS, there is no passing of Session between them.
A large number of systems have been applied to asp before. In the upgrade process, if asp is completely abandoned and rewritten, it will be too much work in the first year and the previous achievements in the second year will not be preserved.
So Microsoft came up with a shared solution for Session, but this document only explains the principle, and does not say the specific steps, so I write to describe the process.

To briefly explain the principle, the Session system 1 between asp and asp.net is stored in the database for sharing

1. Create 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 file is unzipped, four files will be generated. Do the following for each file.
Copy global.asa to the system root directory and open the file. Modify Application("SessionDSN") to the appropriate database link string. If the system already has global.asa, add the following:
Application("SessionDSN") = "initial catalog=SqlServerName;persist security info=False;user id=sa;password=****;packet size=4096"
Add this item to the system's Web.config file
< add key="SessionDSN" value="data source=SqlServerName;initial catalog=SessionDemoDb;persist security info=False;user id=SessionDemoDbUser;password=****;packet size=4096" > < /add >
And change its value to the appropriate database link.
Copy the other two dll files to the system directory (or other appropriate directory)

3. Disable Session option from Asp in IIS
Open IIS, select Site, and then select Properties - > Home directory - > Configuration - > Application options to remove the check check before session status is enabled. The diagram below:
screen.width-350)this.width=screen.width-350" border=0 >

4. Install SessionUtility.dll
Microsoft Visual Studio.NET 2003\SDK\v1.1\Bin. Microsoft Visual Studio.NET 2003\SDK\v1.1\Bin
In the command prompt window, execute gacutil /i SessionUtility.dll (if this fails, write the path to both files).

Register SessionUtility.dll as an Com object
Again, to find the file regasm.exe, normally in the directory WINNT\Microsoft.NET\Framework\v1.1.4322
regasm.exe SessionUtility.dll /tlb:SessionUtility.tlb In the command prompt window, execute regasm.exe SessionUtility.dll /tlb:SessionUtility.tlb (write the path to both files if this fails)
This results in an tlb file that can be invoked as a normal Com component.

6, Register SessionManager.dll
This is easy. In the command prompt window, execute regsvr32 SessionManager. dll

7, For NTFS, please find SessionMgr.dll, right click, Properties, and set IUSR_ < machine_name > Permissions are set to be readable and executable. So far, we have been able to realize the Asp and Asp. net Session sharing between, so how to use in Asp, we want to use as follows: < br > Page start < br > Dim Session < br > Set Session = Server.createObject("SessionMgr.Session2") < br > Session("UserID") = ... < br > ... < br > ... < br > ... < br > End of page < br > Set: Session = Nothing 'Session: Set: Session = Nothing' < br > First, we need to add a reference to SessionUtility < br > Then, when coding, turned out to be such inheritance public class WebForm1: System. Web. UI. Page, modified to public class WebForm1: MSDN. SessionPage < br > This allows the form Session("UserID") to be used in the coding process. Note: Although Session implements sharing, the usage syntax of Session, as opposed to the new additions in.net, is not implemented, after all, asp is taken care of < br > Session.Remove, for example, will not work. < p id="TBPingURL" > Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1621435 < /p > < br > < /machine_name >


Related articles: