How to implement ASP and ASP to share session

Source: Internet
Author: User

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

In. NET, the session storage mechanism is not the same as the ASP storage mechanism, although you can run both ASP and ASPX under the same IIS, but they cannot pass the session between them.
Before the large number of systems applied to the ASP, during the upgrade process, if completely discard the ASP to rewrite, the workload is too large, and the previous results can not be saved.
So Microsoft proposed a session sharing solution, just this document light description principle, and did not say specific steps, thus, I wrote a description of the process.

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

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

After extracting the file, 4 files will be generated, respectively, to do the following.
Copy the 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 "></add>
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 the session option for ASP in IIS
Open IIS, select the site, select Properties---Home directory, configuration-by-application option, and enable the check mark removal before session state is enabled. Such as:
screen.width-350) this.width=screen.width-350 "border=0>

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

5. Registering SessionUtility.dll as COM object
Similarly, to find the Regasm.exe file, under normal circumstances in the winnt\microsoft.net\framework\v1.1.4322 directory
In the command Prompt window, execute Regasm.exe sessionutility.dll/tlb:sessionutility.tlb, (if the execution fails, write the path to all two files)
This produces a TLB file that can be called as a normal COM component.

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

7, if the system is NTFS format, please find SessionMgr.dll, right click, properties, set iusr_<machine_name> permissions to be readable and executable. <br><br> at this point, we have been able to implement the ASP and ASP between the session shared, then how to use <br><br> in ASP, we want to use: <br> Page start end <br>dim Session <br>set session = Server.CreateObject ("Sessionmgr.session2") <br>session (" UserID ") = ... <br>.. <br> <br&gt. <br> End of page <br>set Session = Nothing ' Remember to release oh <br& Gt;<br> and in ASP. NET, we use the following: <br> first, we want to add a reference to Sessionutility <br> and then, when encoding, it turns out that this inherits the public class WebForm1:System.Web.UI.Page, modify to public class webform1:msdn. Sessionpage <br> This allows you to use the form of the session ("UserID") during the encoding process. <br><br> Note: Although the session is shared, the use of the session syntax, relative to the new part of. NET, is not implemented, after all, to take care of ASP <br> For example, Session.remove, it can't be used. <br><br><p id= "Tbpingurl" >trackback:http://tb.blog.csdn.net/trackback.aspx? Postid=1621435</p> <br></machine_name>

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.