Solved

Accessing ASP session in C# class library

Posted on 2008-10-25
9
1,386 Views
Last Modified: 2012-06-21
Hi,

I am trying access session created on ASP (not ASP.Net) on C# class library.  I tried using system.web.context.current.session["<Sessionid."] but its throwing error " Object Reference must set to an object". C# class unable to find session created in ASP.

Thanks,
Gaurav
0
Comment
Question by:gaurav0508
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 12

Expert Comment

by:roverm
ID: 22804462
Did you try to get the session first using: HttpContext.Current.Session ?

0
 

Author Comment

by:gaurav0508
ID: 22804541
Yes we tried it.
0
 
LVL 14

Expert Comment

by:Ramuncikas
ID: 22804600
I don't think it is possible. ASP and ASP.NET sessions are two different isolated objects in memory and they cannot "see" each other.
Though there are techniques to exchange session variables between ASP and ASP.NET applications and vice versa, I don't think this will suite you.

Could you please explain how you are using a .NET class library in ASP application?

R
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

Accepted Solution

by:
jangins101 earned 145 total points
ID: 22804625
The only way that I've found to share Sessions between ASP and ASP.NET has been through taking all the session variables and placing them in a form and submitting that form to an ASP.NET page, that grabs each of those variables and sets them as ASP.NET Session variables. (Found this site that explains it too. http://www.eggheadcafe.com/articles/20021207.asp)

The other way I saw would be to use a database to store the data, which I saw at http://msdn.microsoft.com/en-us/library/aa479313.aspx.

Hope this helps.
0
 

Author Comment

by:gaurav0508
ID: 22806216
For Ramuncikas:

What we are doing is calling C# dll  from ASP pages. C# dlls are kept in GAC.
Session is created on ASP pages. Now these session variable we need to use in C# class. As mentioned we used System.web.context.current.session but its not working.

I tried sending session from ASP to ASP.net (http://www.eggheadcafe.com/articles/20021207.asp) but again I am unable to access the session in C# class. Basically I need to call C# functions from ASP so even if I send session from ASP to ASP.net I have to come back to ASP page to call C# dll.
I did that as well but I think we lose session when we come back from ASP.Net page to ASP.




0
 

Author Comment

by:gaurav0508
ID: 22806221
Jaggins101:

I have already tried http://www.eggheadcafe.com/articles/20021207.asp and managed to get session on ASP.net page but I need to call C# functions from ASP so even if I send session from ASP to ASP.net I have to come back to ASP page to call C# dll.
I did that as well but when I tried to access session in C# I couldn't do it.I think we lose session when we come back from ASP.Net page to ASP.

0
 
LVL 14

Expert Comment

by:Ramuncikas
ID: 22808315
C# class library relies on caller's session, but when caller is ASP application it does not know what kind of object is that and how to work with it. C# class library only knows HttpSession object, but ASP application does not use one.

The only chance would be to pass actual values C# class needs. If you're the author of C# class library then you can rewrite it or add some overloads to functions, otherwise I guess you're stuck.

Maybe you could be more specific about what dlls you try to use. If these are some standard ones maybe you could find some workaround.

R
0
 
LVL 14

Expert Comment

by:Ramuncikas
ID: 22808437
One quick thought.

As suggested by Jaggins101 your ASP page could create and fill a form with session variables. Additionally you could add one (or more) form elements to pass some value that will denote what or which function to call from C# class library. From ASP you post this from to ASP.NET page or HttpHandler you create.

This ASP.NET page or HttpHandler would create session automatically upon request. It would read all passed variables from form and would setup session. Additionally from a value you pass it would call needed function from C# class library. If you need some result of a function call this same page or HttpHandler could convert it to a well known form (XML) and pass it back to ASP page as response.

I'm mentioning HttpHandler many times because it's more lightweight and it's easier to render response with it than with a page.

Ramuncikas
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question