Access session variables across asp and aspnet

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello!

I am trying to access session variables that are created in asp application
in an aspx file next to them.

I tried the solutions that are out there with no luck. One suggested
creating an sql table and populating it with session data. But the calling
page fails two out of three times with errors and the one time it works, it
does not save the session variables that have been created and I need.

Is there any easy way to reference these? Your help is very much
appreciated. Thank you!

-Bahman
 
One suggested
creating an sql table and populating it with session data. But the calling
page fails two out of three times with errors and the one time it works,
it
does not save the session variables that have been created and I need.

Is your ASP page able to save the session variables?
Is your aspx page able to open a connection?
What does your command text and table structure look like?
And what error do you get?

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
 
Bahman,

Probably I can find an answer, however the time I did this is long behind
me.

A much better newsgroup to get actual information about your question is

microsoft.public.dotnet.framework.aspnet

I hope you get a good answer.

Cor
 
Can you post the code that's causing the problem? Since you mention that
two of three are causing problems, It's probably not a Cookies issue, but in
order to use Session state you'll need this. I wouldn't automatically opt
for using Sql Server to store the data - this is 'a' fix for some issues,
but by NO means is it the best way to handle every situation and in most
cases, it's probably NOT the way to go.At best you introduce another
dependency.

As far as the failure, first off, what exception is being thrown? Next, is
the problem settting the variables , retrieving them, or both?
Typically you can just set a session variable liek

Session["Whatever"] = Whatever;

You can retrieve it by using

if(Session["Whatever"] != null){
Whatever = Session["Whatever"] as TypeOfWhatever;
} //make sure that you ge the type right, this can cause invalid cast
exceptions otherwise. And by using the As, keyword, you won't throw an
exception if the session value is null. However you may well want to throw
an exception - in which case you'd use (TypeOfWhatever)Session["Whatever"]
instead.

However, if you use this approach, you can to make sure spelling is correct
which is often a problem. I'd create a constants class and set the
"Whatever" in there so you can reference the session variable and get
intellisense to make sure typos aren't causing the problem
SomeType Whatever;
Whatever = Session[Constants.SomeSubsection.Whatever] as SomeType;

Typos probably aren't the problem here since it works sometimes and others
it doesn't, but I mention it just as a possibility. Also, are you sure that
the variables are getting set correctly (no If statements or conditionals
that could be setting it in some cases and not in others). Are you handling
the post back correctly? Is it 'working' on page_load but not on postbacks?
And finally, what's the error - is it just having session variables or is it
in referencing them? If it's in referencing them, then the cast vs. As issue
could well be the problem (or a problem)

If you would post the code, I can probably be a little more help.

Cheers,

Bill
 
Bahman - I may have misread your post the first time through - is your
problem getting the values stored in a database - or is it just referencing
Session variables - what I mean is is the reason you're using the db b/c you
couldn't get session to work and now that doesn't work either? Or can you
get session to work otherwise, but when you try to store them in the db,
that's blowing up?
 
Bill,

Yes, I got it to work.

Thank you all for your help!

The problem was with me. I had many different syntaxes to work with. It was
a simple rewrite to get vb to work from asp to aspnet and from there to c#.

If you are interested: there is an issue with having to rewrite large
quantities of code. Aspnet assumes that you are starting from scratch. Many
times, that is not true. So, what I am trying to do is maintain what is
already there and expand across different platforms.

This worked well. I am very happy about that.

Thank you very much! Happy Wednesday!

-Bahman
 
Back
Top