473,788 Members | 3,101 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do u set classic ASP session variables from an ASP.NET application???

My project currently requires that I integrate an ASP.NET application with
an ASP application. One of the issues I'm having is that I have some very
long strings being created in an ASP.NET application that need to somehow
appear in a classic ASP session. The strings are too long for cookies or
URLs and I'd like to avoid using a database or someother temporary server
storage.

So far what I've come up with is a .NET class that "spoofs" a post to an ASP
page specifically designed to load its post data into the session. The post
spoof involves a System.NET.HTTP WebRequest object, copying the HTTP headers
from HTTPContext.Cur rent.Request, and creating a post data byte array.

What i've found so far is that even though it would appear my HTTPWebRequest
object has a cookie in its headers containing the ASP session identifier for
an already established ASP session, the request causes a new ASP session to
be created. Also, it appears that my post data isn't making it to the ASP
page that is responsible for mapping the post data into the ASP session.

Any advice or information would be greatly apreciated//

Below is the source code from my current class
=============== =============== =============== ===============
/// <summary>
/// <c>ASPSession </c> is an adapter for moving data from the .NET runtime
to a traditional ASP session
/// This is accomplished by maintaining a local collection of name-value
pairs, then including these pairs in
/// a POST request to a traditional ASP page that is ultimately responsible
for committing the name-value pairs to an ASP session
/// ** this means that in order to function correctly, this class requires
the existence of the described receiver ASP page
///
/// Sample VBScript code for ASP receiver page
/// <%
///
/// for each formKey in Request.Form
/// if ( InStr( Upper( formKey ), "SESSIONKEY ." ) ) then
/// session( Replace( Upper( formKey ), "SESSIONKEY .", "" ) ) =
Request.Form( formKey )
/// end if
/// next
///
/// %>
/// </summary>
public class ASPSession
{

#region Fields

private const String _ASP_RECEIVER_P AGE = "RuntimeToSessi onReceiver.asp" ;
private const String _ASP_RECEIVER_C ONTENTTYPE =
"applicatio n/x-www-form-urlencoded";
private const String _ASP_SESSIONKEY _POST_PREFIX = "SessionKey .";
private StringDictionar y _aspSessionValu es;
private HttpWebRequest _aspReceiverReq uest;

#endregion

#region Constructors

/// <summary>
/// Creates a new instance of ASPSession
/// </summary>
public ASPSession()
{
_aspSessionValu es = new StringDictionar y();
configureASPRec eiverRequest();
}

#endregion

#region Public Members

/// <summary>
/// Gets or Sets name-value pairs for submission to an existing ASP
session
/// </summary>
public String this[ String ASPSessionKeyNa me ]
{
get
{
if( _aspSessionValu es.ContainsKey( ASPSessionKeyNa me ) )
{
return _aspSessionValu es[ ASPSessionKeyNa me ];
}
else
{
return null;
}
}
set
{
if( _aspSessionValu es.ContainsKey( ASPSessionKeyNa me ) )
{
_aspSessionValu es[ ASPSessionKeyNa me ] = value;
}
else
{
_aspSessionValu es.Add( ASPSessionKeyNa me, value );
}
}
}

/// <summary>
/// Executes an HTTP POST request containing the current collection of
name-value pairs to the ASP receiver page
/// * If it is determined that there are no name-value pairs to post, no
request is made.
/// </summary>
public void SetVars()
{
if( _aspSessionValu es.Count > 0 )
{
setHeaders();
Byte[] postData = getPostData();
if( postData != null )
{
_aspReceiverReq uest.ContentLen gth = postData.Length ;
Stream sendStream = _aspReceiverReq uest.GetRequest Stream();
sendStream.Writ e( postData, 0, postData.Length );
sendStream.Clos e();
HttpWebResponse response = ( HttpWebResponse )
_aspReceiverReq uest.GetRespons e();
StreamReader reader = new StreamReader( response.GetRes ponseStream() );
String test = reader.ReadToEn d();
reader.Close();
}
}
}

#endregion

#region Private members

private void configureASPRec eiverRequest()
{
String receiverURL;
if( String.Compare( HttpContext.Cur rent.Request.Se rverVariables[
"HTTPS" ], "on", true ) == 0 )
{
receiverURL = "https://";
}
else
{
receiverURL = "http://";
}
receiverURL += HttpContext.Cur rent.Request.Ur l.Host + "/" +
_ASP_RECEIVER_P AGE;
_aspReceiverReq uest = (
HttpWebRequest )System.Net.Htt pWebRequest.Cre ate( receiverURL );
_aspReceiverReq uest.ContentTyp e = _ASP_RECEIVER_C ONTENTTYPE;
_aspReceiverReq uest.Method = "POST";
}

private void setHeaders()
{
_aspReceiverReq uest.Headers.Cl ear();
foreach( String headerName in HttpContext.Cur rent.Request.He aders )
{
try
{
_aspReceiverReq uest.Headers.Ad d( headerName,
HttpContext.Cur rent.Request.He aders[ headerName ] );
}
catch( ArgumentExcepti on )
{
// Some headers are restricted (why, i'm not sure) and will cause an
ArgumentExcepti on to occur
}
}
}

private Byte[] getPostData()
{
String sessionKey;
String postDataString = String.Empty;
foreach( DictionaryEntry aspSessionEntry in _aspSessionValu es )
{
sessionKey = aspSessionEntry .Key.ToString() ;
if( sessionKey.Leng th > 0 )
{
postDataString += String.Format(
"&{0}={1}",
HttpUtility.Url Encode( String.Format( "{0}{1}",
_ASP_SESSIONKEY _POST_PREFIX, sessionKey ) ),
HttpUtility.Url Encode( aspSessionEntry .Value.ToString () )
);
}
}
if( postDataString. Length == 0 ) return null;
postDataString = postDataString. Substring( 1 );
return Encoding.ASCII. GetBytes( postDataString );
}

#endregion

}
Nov 19 '05 #1
0 1829

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1660
by: Wynter | last post by:
I've been smacking into one brick wall after the next in converting some of my code from ASP Classic to ASP.NET. This one is a real bugger. I use Session Variables to help with User Security. If they drop a key Session Variable then they are signed out of the application. I create this session variable at Signon in Classic ASP code, but as I am finding out the hard way later ASPX code modules are not picking up these session variables. Is...
4
1976
by: Tony | last post by:
I have a classic ASP application that determines whether a user is logged in by examining a Session Variable, Session("LoginId"). Once logged in there is a link to a new search page (.aspx) this page basicaly allows searcing of the database and selection of users from a DataGrid. When a user in the DataGrid is selected (using hyperlink) you are returned to the .asp page, however the Session("LoginId") is empty and the users then have to log...
4
404
by: Chris Newby | last post by:
My project currently requires that I integrate an ASP.NET application with an ASP application. One of the issues I'm having is that I have some very long strings being created in an ASP.NET application that need to somehow appear in a classic ASP session. The strings are too long for cookies or URLs and I'd like to avoid using a database or someother temporary server storage. So far what I've come up with is a .NET class that "spoofs" a...
2
387
by: Wynter | last post by:
I've been smacking into one brick wall after the next in converting some of my code from ASP Classic to ASP.NET. This one is a real bugger. I use Session Variables to help with User Security. If they drop a key Session Variable then they are signed out of the application. I create this session variable at Signon in Classic ASP code, but as I am finding out the hard way later ASPX code modules are not picking up these session variables. Is...
0
10172
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.