473,387 Members | 1,290 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

C# Web-App: problem with session variable

109 100+
Hi all,

I really need some help. I have a asp.net web project using c#.

I have put one of my datafield in session in one webform and I am calling that same datafield of the session to another web form within a same project.

I worked before and now all of a sudden I am getting null value in my second form when i try to extract from session variable.

As far as I know I haven't change anything in this project.

and my syntaxt is:
Expand|Select|Wrap|Line Numbers
  1. Session["qid"] = qid; ....................webform1
  2.  
  3. string getid = Session["qid"].ToString();..............webform2
  4.  
what should I do to resolve this?

Thank You,
Dec 13 '07 #1
12 3354
Shashi Sadasivan
1,435 Expert 1GB
is this code

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

in the page load of webform2?

you shud be able to debug and find out the value of that session variable before getting redirected from webform1 to webform2. Have you tried it?
Dec 14 '07 #2
arial
109 100+
I am calling string getid = Session ["qid"].ToString(); to one of the method that I call on page load.

like,
Expand|Select|Wrap|Line Numbers
  1. page load()
  2. {
  3. Getpdfs();
  4. }
  5. public void pdfs()
  6. {
  7. string getid = Session ["qid"].ToString(); 
  8. }
  9.  
yes.. On my webform1 I can see the value getting into session during the debugging but when it comes to webform 2

string getid = session["qid"].Tostring();

getid come with null value.
Dec 14 '07 #3
arial
109 100+
Ok. here I found something strange.

I can get session variable to my webform3 because I have several webforms withing same projetc.

But, I can not get session variable on webform 2.

How can this possible? And I can not find anything wrong with my webform2.

Please help me if any one of you have any idea on this.

Thank You,
Dec 14 '07 #4
Shashi Sadasivan
1,435 Expert 1GB
Your code:
Expand|Select|Wrap|Line Numbers
  1. page load()
  2. {
  3. Getpdfs();
  4. }
  5. public void pdfs()
  6. {
  7. string getid = Session ["qid"].ToString(); 
  8. }
Is it because of this reason

Modification, notice the change of the method !!!!
Expand|Select|Wrap|Line Numbers
  1. page load()
  2. {
  3. Getpdfs();
  4. }
  5. public void Getpdfs() //notice the change
  6. {
  7. string getid = Session ["qid"].ToString(); 
  8. }
Dec 14 '07 #5
arial
109 100+
I just a typo error on my previous post about the function.

I do have the function's correct name but it not working.
Dec 14 '07 #6
Plater
7,872 Expert 4TB
Do you have any Session.Abandons() in your pages?
Or anything that would tell the client browser to drop the cookie?
Dec 14 '07 #7
arial
109 100+
I am not sure what is Session.Abandons() .

but, what I just recently discover is,

I can get session variable to my second form if in my hyper link I have address like: http://localhost/form2.

but if I replace my localhost to IP address I can't get session variable.
like, http://10.10.10.10/form2 does not give me session variable.

Why it would behave right with localhost and won't work with IP address?

Thank You,
Dec 14 '07 #8
Plater
7,872 Expert 4TB
I am thinking it is client side.
There is a special header that gets passed in the request/responses that contains the session id for the user.
If the browser doesn't send the special header, the server assumes it's a new "user" and gives it a new session id, giving the appearance that the session values have been lost.
The browser might not understand it needs to send the header if you switch up the URL address.
Dec 14 '07 #9
arial
109 100+
I think URL address is same like,

home page is like,

http://10.10.10.10/form1

there is a link on form1 which takes to form2

with a url

http://10.10.10.10/form2.

if I replace my ip address with localhost it works but if I have IP address it won't work.

Thank you
Dec 14 '07 #10
Plater
7,872 Expert 4TB
Does it work with http://127.0.0.1/ ?
Dec 14 '07 #11
arial
109 100+
No. and I get this error message when I use my IP Address on hyperlink.

Expand|Select|Wrap|Line Numbers
  1. Object reference not set to an instance of an object. 
  2. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
  3.  
  4. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
  5.  
  6. Source Error: 
  7.  
  8.  
  9. Line 42:         {
  10. Line 43:             // Put user code to initialize the page here
  11. Line 44:             getqid = Session["qid"].ToString();            
  12. Line 45:             buildQuickcheck();
  13. Line 46: 
  14.  
  15.  
  16. Source File: d:\devsite\tap\checkoutform\qcheck.aspx.cs    Line: 44 
  17.  
  18. Stack Trace: 
  19.  
  20.  
  21. [NullReferenceException: Object reference not set to an instance of an object.]
  22.    CheckOutForm.QCheck.Page_Load(Object sender, EventArgs e) in d:\devsite\tap\checkoutform\qcheck.aspx.cs:44
  23.    System.Web.UI.Control.OnLoad(EventArgs e) +67
  24.    System.Web.UI.Control.LoadRecursive() +35
  25.    System.Web.UI.Page.ProcessRequestMain() +750
  26.  
  27.  
  28.  
  29.  
  30.  
Dec 14 '07 #12
Plater
7,872 Expert 4TB
Yeah, you're def getting a fresh session there (Whether it thinks your a new user or for some reason flushed the existing, I don't know)
What is your session timeout set to?
Also, you know when you do a build of the website your session values are wiped out.

You could try packet watching to see if the session ID stays the same in all the request/responses
Dec 17 '07 #13

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

Similar topics

10
by: Jeremy Ames | last post by:
I have created a web application that uses a custom control and a web service on my local system. I have gotten all of the bugs worked out on my local system and now it is time to move it to the...
0
by: Baruaa | last post by:
hi i m asheesh , can any on ehelp me about this error. Line 57: --> Line 58: <httpHandlers> Line 59: <add verb="*" path="*.vb" type="System.Web.HttpNotFoundHandler,System.Web" />
4
by: James Wong | last post by:
Hi everybody, I'm developing a web service using VB.NET which calls a web form to let user input something. In web service, I use Server.Execute ("WebForm.aspx") to load and execute the web...
0
by: Erick Lopez | last post by:
When I send my web page to browser in ouput windows recibe this message and the web page the error BC32400 Please Help me Auto-attach to process ' aspnet_wp.exe' on machine 'TABLET'...
4
by: Param R. | last post by:
Hi all, we recently upgraded our servers to 2003 and have begun seeing several problems. We have a web services that runs locally and is called by ..aspx pages of other websites. Ever since the...
6
by: Tim Cartwright | last post by:
I have a page that has the login control on it, nothing else. This page inherits from a master page, neither page has any code in it. This page works perfectly when running on the WebDev debug web...
7
by: Jonas | last post by:
Hi. I'm trying to develop a web custom control that uses a programmatically created treeview. My problem is that I get an exception when I try to render the control. With properties do I have to...
2
by: job | last post by:
In a sharepoint setup using smartpart to load our user controls using enterprise blocks (data) we are getting some strange errors (logged to the event log). We dont get the error all the time. When...
2
by: Jeff | last post by:
Hey asp.net 2.0 My asp.net 2.0 project has got a assembly load problem: Some of my web.config settings: <membership defaultProvider="AH_MembershipProvider" userIsOnlineTimeWindow="15">
20
by: =?Utf-8?B?cmtibmFpcg==?= | last post by:
I was executing the steps given in http://suppor.microsoft.com/kb/308359 for testing a sample web service application. However, the following line gives a compilation error: localhost.Service1...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.