Share ASP.NET Context with ASP 2 & 3 – level 400

We all have ASP applications that we need to extend with ASP.NET. Unless our functionality is wrapped in COM, we may have to rewrite some in .Net. Wouldn’t it be nice if we could rewrite common app functionality in .Net and then reuse it in the ASP? I’ve worked up a sample that does just that. I have a web service that exposes the Session object, so now ASP can query the ASP.NET’s Session object (this method could also be used for the Cache object, Application, etc.). For this to work, ASP has to be in the same ASP.NET session. That means that the cookie “ASP.NET_SessionId” must exist on the ASP and ASP.NET side, and it must contain the same session id. Using the Soap Toolkit v.3, I make the web service calls. One of the web service methods returns the ASP.NET SessionID. I use this to manually make a Set-Cookie header in ASP because ASP natively HTML Encodes cookie names (would result in %20, or whatever for the . and the _). Then in subsequent web service calls, I add a soap header to include the cookie with the ASP.NET session id, and this allows every web service call to participate in the same session, so all the data remains coherant.

I was so excited when I got this to work, I had to share. If you search for this topic on Google, there are thousands of people who have this problem.

Related

Chris Kinsman
9:51 pm on June 5, 2004

Fairly inefficient and unless you change the connection limit it limits you to two connections to the web service at any point in time…

Jeffrey Palermo
10:46 am on June 6, 2004

To be honest, I hadn’t thought about the connection limit. I’m still searching for the best way to share sessions with ASP and ASP.NET.

Jeffrey Palermo
6:26 am on June 8, 2004

The method I described above is a good way to make web service calls participate in the same session. This method does not scale for complete Session sharing if every hit of an ASP app is making a web service call. For high traffic like that, I think putting session information in sql server is a better option. And if all you need is the currently logged on user, then adding a cookie with the username is a good option.