By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,364 Members | 1,518 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,364 IT Pros & Developers. It's quick & easy.

.Net session variable

100+
P: 109
Hi all,

I have problem with session variable on .net web form.

I am saving ID in session to pull up the other .net web form it works fine with my development environment but as soon as I put my application in production environment but session varible doesn't work.

this what I have in session:

String getid = Session["qid"].ToString();

and my "getid" comes null in production.

It is very urgent I am suppossed to release this application and I got stuck with this problem.

Please please can anyone explian me this situation?

Thank you Thank You
Apr 3 '08 #1
Share this Question
Share on Google+
9 Replies


Shashi Sadasivan
Expert 100+
P: 1,435
Technically you should be typecasting the session tot a String type;

String getid = (String)Session["qid"];

moreover if getid is being thrown at null,
then Session["qid"] should be null, and Session["qid"].ToString should throw an exception

The result you see may be IIS specific. Have you defined the session variables in global.asax ?
Apr 3 '08 #2

kunal pawar
100+
P: 297
First trace ur session set properly or not
Apr 3 '08 #3

100+
P: 109
I tried to dubugg and this is what i have found out.

My session variable get to my another form which doesn't need this session variable but I am getting null in a webform where I need this session variable.
for example this is what I have;

Expand|Select|Wrap|Line Numbers
  1. form1:
  2.  
  3. session["qid"] = qid...............this one does gets the value of qid
  4.  
  5. Form2: 
  6.  
  7. string test = Session["qid"].ToString(); ...................test does gets value of qid
  8.  
  9. form3:
  10.  
  11. string getid = Session["qid"].ToString(); ..................getid is null here.
  12.  
It is just not making any sense to me.

How would I initialize session variable in globas.aspx file?
Apr 3 '08 #4

balabaster
Expert 100+
P: 797
How would I initialize session variable in globas.aspx file?
I'm betting you don't have a global.asax file in your web application...

In Solution Explorer, right click your application and click Add/New Item...
Select a Global Application Class (the name will be Global.asax in the edit field at the bottom).
Click Add

In the Global.asax.cs file which comes up, in the Session_Start routine initiate your variables as such:

session["Field1"] = "";
session["Field2"] = "";
//etc.

When I've run across this problem in the past, that's usually what I've missed.
Apr 3 '08 #5

Plater
Expert 5K+
P: 7,872
I don't think i've ever declared Session variables in the global.asx page.
I suppose that would mean you don't need to check for null, just for empty strings.
A lot of people seem to be having trouble with their Session objects lately and I can't reproduce any of their problems.
Apr 3 '08 #6

balabaster
Expert 100+
P: 797
I don't think i've ever declared Session variables in the global.asx page.
I suppose that would mean you don't need to check for null, just for empty strings.
A lot of people seem to be having trouble with their Session objects lately and I can't reproduce any of their problems.
It's been a whlie since I used session objects, but when I had this issue in the past, that's exactly the way I've solved it.
Apr 3 '08 #7

100+
P: 109
Thank you all for your reply.

I declare session to the global file so, now i am not getting an error message but it is not displaying the data.

need more help on to resolve this.

Thank you
Apr 3 '08 #8

kunal pawar
100+
P: 297
check u allowed session for this page, coz there is property in @page to allow session. another thing check qid is empty / null
Apr 4 '08 #9

100+
P: 109
Thanks Kunal,

I do have string qid = "";

and what property to check for allowing session at page?

Thank You
Apr 4 '08 #10

Post your reply

Sign in to post your reply or Sign up for a free account.