asp.net ASP implementation
The original ASP dialog can only save the conversation data in memory. To save the conversation data to SQL Server, you need to write a custom visual Basic 6.0 COM object instead of the current dialog object to manage the dialog state. The COM object is initialized at the start of each Web request and the dialog data is loaded back from SQL Server. When the ASP script completes, the object terminates and the dialog state is returned to SQL Server.
The primary purpose of the Visual Basic 6 COM Session object is to provide access to the internal objects of Microsoft Internet Information Server (IIS). The Visual Basic 6 com Dialog object uses the MySession class of the sessionutility component to save the dialog state, and the Sessionutility Sessionpersistence class is used to load and save the dialog data to the SQL Server. Use the Regasm.exe tool to expose mysession and Sessionpersistence classes as COM objects. The Regasm.exe tool can register and establish a type library for COM clients to use the framework component classes.
State information is being loaded back into the object's constructor. The constructor (Class_Initialize) first retrieves the dialog cookie, the dialog Timeout setting (sessiontimeout), the database connection string (SESSIONDSN) from the Application object, and establish an instance of the MySession class to hold the dialog data. The constructor then attempts to load the dialog data from SQL Server using the given cookie again. If there is no dialog information in SQL Server, or if the conversation is terminated, a new cookie is generated. If SQL Server returns the dialog state data, the dialog state information is saved in the MySession object.
Private Sub Class_Initialize ()
On Error GoTo ErrHandler:
Const method_name as String = "Class_Initialize"
Set mysessionpersistence = New sessionpersistence
Set Myobjectcontext = GetObjectContext ()
Mysessionid = Readsessionid ()
mydsnstring = Getconnectiondsn ()
Mytimeout = Getsessiontimeout ()
Myisnewsession = False
Call Initcontents
Exit Sub
ErrHandler:
Err.Raise Err.Number, Method_name & ":" & Err.Source, Err.Description
End Sub
Private Sub initcontents ()
On Error GoTo ErrHandler:
Const method_name as String = "Initcontents"
If Mysessionid = "" Then
Set mycontentsentity = New mysession
Mysessionid = Mysessionpersistence.generatekey
Myisnewsession = True
Else
Set mycontentsentity =mysessionpersistence.loadsession (Mysessionid, mydsnstring, Mytimeout)
End If
Exit Sub
ErrHandler:
Err.Raise Err.Number, Method_name & ":" & Err.Source, Err.Description
End Sub
If the object instance is outside the scope of the script, the destructor (Class_Terminate) is executed. The destructor uses the Sessionpersistence.savesession () method to hold the dialog data. If this is a new conversation, the destructor sends the new cookie back to the browser.
Private Sub Class_Terminate ()
On Error GoTo ErrHandler:
Const method_name as String = "Class_Terminate"
Call Setdataforsessionid
Exit Sub
ErrHandler:
Err.Raise Err.Number, Method_name & ":" & Err.Source, Err.Description
End Sub
Private Sub Setdataforsessionid ()
On Error GoTo ErrHandler:
Const method_name as String = "Setdataforsessionid"
Call Mysessionpersistence.savesession (Mysessionid,
Mydsnstring, mycontentsentity, myisnewsession)
If myisnewsession Then Call Writesessionid (Mysessionid)
Set mycontentsentity = Nothing
Set Myobjectcontext = Nothing
Set mysessionpersistence = Nothing
Exit Sub
ErrHandler:
Err.Raise Err.Number, Method_name & ":" & Err.Source, Err.Description
End Sub
Routines
The routines are designed to add and display a number. Regardless of which page is loaded, numbers are increasing as numeric values are stored in SQL Server and shared between ASP and ASP.net.
Steps to establish a routine
1. Create a new database Sessiondemodb.
2. Create a new Table Sessstate (OSQL.EXE-E-D sessiondemodb-i session.sql).
3. Create a new virtual directory demo.
4. Close the ASP dialog in the ASP Configuration page.
5. Copy web.config, testpage.aspx, Global.asa, testpage.asp, and globalinclude.asp to the virtual directory.
6. Updates the DSN string settings in Global.asa and web.config. The dialog timeout setting is optional and defaults to 20 minutes.
7. Installs the SessionUtility.dll to the Global component cache (gacutil/i SessionUtility.dll).
8. Use Regasm.exe to expose SessionUtility.dll as a COM object (Regasm.exe sessionutility.dll/tlb:sessionutility.tlb).
9. Copy the SessionManager.dll to the local directory and use Regsvr32.exe registration (regsvr32 SessionManager.dll).
10. Gives the iusr_< computer name > account permission to read and run Access SessionMgr.dll.
Steps to run a routine
1. Open Microsoft Internet Explorer.
2. Load the testpage.asp for the traditional ASP. The number "1" will appear in the Web page.
3. Click the refresh of Internet Explorer to reload the page. The numbers will increase.
4. Change the URL for asp.net to testpage.aspx. The number is still increasing.
5. If you start with testpage.aspx, the procedure is the same.
Inserting a COM object in an existing ASP application
A common habit of developing ASP applications is to include a file at the beginning of each script to share code and constants. The final way to insert a custom dialog object is to include the sample code in the public inclusion file. The last step simply replaces all references to the dialog object with a custom dialog variable name.
Limitation/Improvement
ASP applications that hold COM objects in the session object are not supported in this scenario. In this case, in order to use a custom dialog object, a custom scheduler is needed to serialize/parallelization the state. Also, this scenario does not support saving arrays of string types. Some additional work can be done with this feature: using the Join function of Visual Basic 6.0 to concatenate an array element into a string before saving it to a dialog object, you can use the Split function of Visual Basic 6.0 to decompose the string into a separate array element. In the. NET Framework component, the join and split methods make the members of the string class.
Conclusion
Asp. NET presents new programming paradigms and architectures, and offers many advantages over traditional ASP. Although the process of porting ASP to asp.net is not simple, asp.net a better programming model and higher performance will make the conversion process worthwhile. In addition to saving a special case of COM objects in the Session object, the approach discussed in this article provides a simple solution for implementing migration.