Research on the Application of building session data bridge between ASP and ASP. NET Based on Web Services

Source: Internet
Author: User
Tags classic asp
The purpose of this article is to provide a feasible solution to integrate and manage existing ASP Program To ASP. NET. This application solves

The solution tries its best to update the current session in the ASP Web server memory to ASP. NET in an iterative update method.

Background:

The existing company's product OA was developed using ASP earlier technology and needs to be used for data interaction with the latest Asp.net products. Existing ASP applications

"ASP sessions" is often used, which is a classic built-in ASP mode, that is, to allow temporary data storage in the web server memory, the biggest limiting factor is

The session Status of ASP depends on the specific server. Another wider solution is that many web servers may not point

Any network server. In fact, all Web servers are in the same farm, so any session Status in the memory will not automatically follow the request. Each

ASP servers provide their own session status, unless the user accidentally returns to the unified server, resulting in system session loss.

By using server management products (such as bigip), users are forced to agree to the Web farm on the server to solve the problem of ASP seesion in memory caused by server relationship.

. For this purpose, a cookie is used on the client and on the server, allowing users to directly return to

Each reqeust. This restricts scalability, improves maintainability, and avoids the risk of Server failure (for example, session loss Server failure ).
 
The emergence of Microsoft Asp.net has finally solved this problem. We can store session information to Web server, database, or other domains.

Server. Yes. The problem is solved. We need to use ASP.Code? All away? If this is done, it will take a lot of money to re-use. net.

Rewrite ASP. It seems that it is still not feasible. Another better solution is to use iterative methods to partially transplant code to a new model, which is better than rewriting ASP code.

In the process, if the old ASP code and the new Asp.net code can have a common session State to maintain normal operation, then throughout the lifecycle

This will help you better avoid risks. The following solutions are provided to solve the problems caused by server relationships using the classic ASP sesssion.

Problem.

1. User-defined groups or using ASP/ADO scripts to directly read and write user session data to the database;

2. User-defined components directly access Asp.net seesion data;

3. Create a bridge sharing session between ASP and Asp.net through web servieces;

In this article, we will discuss the last solution, which will also include some Web Services and ASP/ADO custom databases, and the basics of ASP session pool.

Compare the performance data.

ASP to ASP. NET bridge/Web-service solution

This solution simply implements a web services bridge from ASP to Asp.net. If you need to use a database, you only need to perform simple configuration (web.

Congfig and aspstate database ). The method used to obtain and set the session data in the Code is written in javascirpt. The file must be stored in the local ASP

Program.

This javascirpt implements MSXML, the HTTP feature enables interaction with the server, and is responsible for recycling these cookies to the user workstation.

Advantages:

Supports server-independent web-farm deployment, improves scalability, and easily achieves loose coupling of session states between ASP and Asp.net, and manages sessions with sessioni

(Non-connected HTTP interface, port 80, firewall, etc.) implemented using the time-tested Asp.net session.

Disadvantage: It is slower than ASP session memory pool implementation and database implementation.

 

 

ASP Memory Sharing Mechanism:

Sessions are stored in the web server memory in situations similar to dictionaries or hash tables. asp maintains the session state and raises a special key

User, when the session starts, this key will save the cookie to record every request sent from the client to the server. on the server side, the cookie is obtained.

The session corresponding to the request. One obvious advantage of this mechanism is speed and convenience. All sessions will be on one server.

Storage, so it is very open, but as mentioned above, saving data on one server is also a major drawback, forcing users to return to the same server for retrieval

Session data. This reduces the webform's advantages. It is just a low-cost and elimination strategy. If you only want to implement simple functions, you can use it.

Advantages:

The memory record is seesion, which is fast. The standard ASP code base is used to implement ASP sessions that have been tested over time.

Disadvantages:

It has limited capacity and cannot carry out large-scale network farms (high server dependency). Server failure leads to session loss and high memory usage.

 

 

ASP/ADO database implementation solution

An ASP application server and a database server are established between database connections. Store data in a central database or database cluster

Do not run ASP programs on different servers. This article provides only solutions. The code for obtaining and setting the session can be put into a stored cirpt file, supporting

Using methods obtained based on WebServices, ASP can replace objective cirpt to customize the database mode and directly access ASP. netsession data (such as setting up aspstate ).

Database ).

Advantages:

1. Support server-independent webform deployment;

2. Faster than Asp.net web services;

Disadvantages:

1. Code is customized for execution (relatively rigid );

2. It is slower than ASP sessions shared by memory;

3. database connection is required, from the network server to the database server;

Performance:

The following data lists the performance comparison of each solution. It emphasizes that the memory shared aspsession pool can be used by the shortest small users.

It will also increase additional expenses and costs (unless you are rich ). Reducing Network backhaul and server requests are the only way to improve performance. Microsoft's Web Application

The sort pressure tool is used to execute the test pressure level of 25 threads for 1 minute. From the table, we can see that the memory storage aspsession is better than the other two

Faster.

Method get data (MS) Set Data (MS)
5 values 1 value 5 values 1 Value
In-memory ASP sessions 46 9 34 7
ASP/ASP. NET web service individually 4321 864 3397 679
ASP/ASP. NET web service grouped 711 142 990 198
ASP/ADO database individually 346 69 841 168
ASP/ADO database grouped 163 33 860 172

Code Description ASP mechanism. Create sessioni in ASP as follows:

Session ("sky") = "blue ";
Access these values on other pages using:
VaR skystring = SESSION ("sky ");

New API syntax:

The following syntax will replace the original ASP session syntax, so that JavaScript functions can be encapsulated during bridge usage.
Set a key value pair;
Set a session data of the Kye-value type. The syntax and value are similar to the ASP session syntax. Use the following code to replace the existing ASP session code;

Set sessioni data:
Setsessionvalue ("sky", "blue ");
Get session:
VaR skystring = getsessionvalue ("sky ");
In this method, we recommend that you use
Set multiple key-valus Pairs
The maximum overhead of these methods is to set each key-value and then return it to WebService. We recommend that you use the following method (when there are more than 3 key-values pairs)
Set session
VaR sessioninfo = newsession ();
Sessioninfo. Add ("sky", "blue ");
Sessioninfo. Add ("Grass", "green ");

Setsession (sessioninfo );

Get session
VaR sessioninfo = getsession ();
VaR skystring = sessioninfo. Item ("sky ");
VaR grassstring = sessioninfo. Item ("Grass ");

Java Script example
<% @ Language = "jscript" %>

<Script language = "jscript" runat = "server" src = "aspsessionws. js"/>

<%
VaR sessioninfo = newsession ();
Sessioninfo. Item ("sky") = "blue ";
Sessioninfo. Item ("Grass") = "green ";
Setsession (sessioninfo );

VaR retrievedsession = getsession ();
VaR ssky = retrievedsession. Item ("sky ");
VaR sgrass = retrievedsession. Item ("Grass ");

Response. Write (ssky + "<br> ");
Response. Write (sgrass + "<br> ");
%>

Visual Basic example
<% @ Language = "VBScript" %>

<Script language = "jscript" runat = "server" src = "aspsession. js"/>

<%
Dim sessioninfo
Set sessioninfo = newsession ()
Sessioninfo. Item ("sky") = "blue"
Sessioninfo. Item ("Grass") = "green"
Setsession (sessioninfo)

Dim retrievedsession
Set retrievedsession = getsession ()
Dim ssky
Ssky = retrievedsession. Item ("sky ")
Dim sgrass
Sgrass = retrievedsession. Item ("Grass ")

Response. Write (ssky & "<br> ")
Response. Write (sgrass & "<br> ")
%>

Web service implementation code

This WebService consists of four simple methods. It supports setting and obtaining separate values in Asp.net sessioni, and simplifies the setting by loading XML.

The complexity of the session variable.

Public String getsessionvalue (string sessionvariable)
Public bool setsessionvalue (string sessionvariable, string sessionvalue)
Public String getsessionvalues ()
Public bool setsessionvalues (string xmlsessionvalues)
To enable the Asp.net web service to support the creation and maintenance of sessions, an Asp.net _

The cookie of sessionid can be used as a bridge to use ASP session code in the response.

[Webmethod (enablesession = true)]

You can also add many WebServices interfaces to implement other functions you want.

ASP bridge implementation:

ASP end bridge is actually a reference to msxml2.serverxmlhttp COM interface to access the Web services server and scripting. Dictionary

For a hash table. Keep a temporary copy Session on the current page.

var XMLHTTP = server. createobject ("msxml2.serverxmlhttp");
XMLHTTP. open ("Post", Surl, false);
var clientcookie = "" + request. cookies ("ASP. net_sessionid ");
XMLHTTP. setRequestHeader ("cookie", "ASP. net_sessionid = "+
clientcookie +"; Path =/; ");
.
.
.
response. cookies ("ASP. net_sessionid ") = httpcookie;
dictionary object conversion
var dctsession = new activexobject (" scripting. dictionary ");
var Re = new Regexp (" deploy the
file aspseesionws. JS must be placed under the ASP program, write the following code in the Asp.net program:

access the Web server through port 80 and write the following functions in the script file to maintain the session status.
function getwebservice (function, parameters)
{< br> var xmlpayload = "";
var Surl = "http://www.xxxx.com/ASPBridge/bridge.asmx" + "/" +
function;

In short, WebService is used to establish sessions from the legacy ASP session to the new Asp.net session, as long as the purpose is to integrate the old program with the new technology,

Although the performance is very important to allow two programs to share the content of a session, there is no perfect way to fully integrate the original program into. net.

Download example: aspbridge.rar (5.59 KB)

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.