How to realize ASP and asp.net sharing session

Source: Internet
Author: User
Tags execution iis modify sql server query visual studio
Asp.net|session in Microsoft. NET, the session's storage mechanism is not the same as the ASP's storage mechanism, although you can run both ASP and ASPX under the same IIS, but they cannot pass the session.
Before a large number of systems applied to the ASP, in the upgrade process, if completely discard the ASP to rewrite, the workload is too large, and the previous results can not be preserved.

So Microsoft proposed a session sharing solution, just this document light explanation principle, and did not say the specific steps of operation, from which I wrote the description process.

Simple explanation principle, the session between ASP and ASP.net is stored in the database to realize sharing

1. Create data table
Open SQL Server Query Analyzer and run the following script to create the 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 documents Session.rar

After the file is decompressed, 4 files will be generated, respectively, as follows.
Copy Global.asa to the system root and open the file, modify application ("Sessiondsn") as the appropriate database link string, and if the system itself already has Global.asa, add the following application in this file:
Application ("sessiondsn") = "Initial catalog=sqlservername;persist security Info=false;user id=sa;password=****; Packet size=4096 "
In the system's Web.config file, add this item
<add key= "Sessiondsn" value= "Data source=sqlservername;initial catalog=sessiondemodb;persist security info=False; User id=sessiondemodbuser;password=****;p acket size=4096 "/>
and modify its value to the appropriate database link.
Copy another two DLL files to the system directory (or other appropriate directory)

3. Turn off ASP's session options in IIS
Turn on IIS, select a site, select Properties-> the home directory-> configure-> application options, and remove the check box before enabling session state. The following figure:
screen.width-350) this.width=screen.width-350 "border=0>

4. Installation SessionUtility.dll
First locate the Gacutil.exe file, typically under the Microsoft Visual Studio. NET 2003\sdk\v1.1\bin Directory
In the command Prompt window, execute gacutil/i SessionUtility.dll (if execution fails, please write down the path of all two files)

5. Register SessionUtility.dll as COM object
Again, to find the Regasm.exe file, in general, under the winnt\microsoft.net\framework\v1.1.4322 directory
In the command Prompt window, execute regasm.exe sessionutility.dll/tlb:sessionutility.tlb (if execution fails, please write down the path of all two files)
This results in a TLB file that can be invoked as a normal COM component.

6, Registered SessionManager.dll
This is very simple, in the command Prompt window, execute regsvr32 SessionManager.dll

7, if it is an NTFS-formatted system, please find SessionMgr.dll, right-click, properties, set the iusr_<machine_name> permissions to be readable and executable.

At this point, we can realize the ASP and ASP.net session sharing, then how to use

In ASP, we want to use the following:
Page Start end
Dim session
Set session = Server.CreateObject ("Sessionmgr.session2")
Session ("UserID") = ...
...
...
...
End of page
Set session = Nothing ' Remember to release OH

And in asp.net, we want to use the following:
First, we want to add a reference to Sessionutility
Then, when encoding, it turns out to be such an inherited public class WebForm1:System.Web.UI.Page, modified to public class WEBFORM1:MSDN. Sessionpage
This allows you to use the form of session ("UserID") in the encoding process.

Note: Although session implementation is shared, but the use of session syntax, compared to the new part of. NET, there is no implementation, after all, to take care of ASP
For example, Session.remove, it can not be used.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.