Session state doesn't work

G

Guest

I have put a string into Session and tried to retrieve it on the next page I
visit but the Session appears empty. I have exactly the same spelling for
both adding and retrieving the value:

Session["name"] = "john";

On the next page:

txtName.Text = Session["name"];

I tried it with .ToString() and in an if statement to make sure it has a
value but it always shows as null.

I have not modified IIS in any way since installing it ( and I have checked
that Session is enabled in the IIS console).

This happens in any of the applications I create in Visual Studio .NET 2003.

Can there be anything else preventing me from using Session state?
 
G

Guest

Hi Karl,

no, I am using Server.Transfer to go from page to page within my application.

Karl Seguin said:
Are you using a Response.Redirect after setting the session? If so, take a
look at:
http://weblogs.asp.net/bleroy/archive/2004/08/03/207486.aspx

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/


cashdeskmac said:
I have put a string into Session and tried to retrieve it on the next page
I
visit but the Session appears empty. I have exactly the same spelling for
both adding and retrieving the value:

Session["name"] = "john";

On the next page:

txtName.Text = Session["name"];

I tried it with .ToString() and in an if statement to make sure it has a
value but it always shows as null.

I have not modified IIS in any way since installing it ( and I have
checked
that Session is enabled in the IIS console).

This happens in any of the applications I create in Visual Studio .NET
2003.

Can there be anything else preventing me from using Session state?
 
J

Juan T. Llibre

Both Response.Redirect and Server.Transfer call Response.End internally,
so you'll have the same problem with either.

Use Server.Execute, instead of Server.Transfer.
That will get rid of your problem.





cashdeskmac said:
Hi Karl,

no, I am using Server.Transfer to go from page to page within my application.

Karl Seguin said:
Are you using a Response.Redirect after setting the session? If so, take a
look at:
http://weblogs.asp.net/bleroy/archive/2004/08/03/207486.aspx

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/


cashdeskmac said:
I have put a string into Session and tried to retrieve it on the next page
I
visit but the Session appears empty. I have exactly the same spelling for
both adding and retrieving the value:

Session["name"] = "john";

On the next page:

txtName.Text = Session["name"];

I tried it with .ToString() and in an if statement to make sure it has a
value but it always shows as null.

I have not modified IIS in any way since installing it ( and I have
checked
that Session is enabled in the IIS console).

This happens in any of the applications I create in Visual Studio .NET
2003.

Can there be anything else preventing me from using Session state?
 
G

Guest

Thank you for the reply Juan,

but I need to know why this is happening on just my computer. If I type the
same code onto another computer and use Server.Transer or Response.Redirect
it works fine, and so I assume that there is a problem with the settings on
my machine.

Juan T. Llibre said:
Both Response.Redirect and Server.Transfer call Response.End internally,
so you'll have the same problem with either.

Use Server.Execute, instead of Server.Transfer.
That will get rid of your problem.





cashdeskmac said:
Hi Karl,

no, I am using Server.Transfer to go from page to page within my application.

Karl Seguin said:
Are you using a Response.Redirect after setting the session? If so, take a
look at:
http://weblogs.asp.net/bleroy/archive/2004/08/03/207486.aspx

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/


I have put a string into Session and tried to retrieve it on the next page
I
visit but the Session appears empty. I have exactly the same spelling for
both adding and retrieving the value:

Session["name"] = "john";

On the next page:

txtName.Text = Session["name"];

I tried it with .ToString() and in an if statement to make sure it has a
value but it always shows as null.

I have not modified IIS in any way since installing it ( and I have
checked
that Session is enabled in the IIS console).

This happens in any of the applications I create in Visual Studio .NET
2003.

Can there be anything else preventing me from using Session state?
 
J

Juan T. Llibre

Please review this KB :
http://support.microsoft.com/kb/312629/EN-US

Although that KB originated in response to a different problem,
it has the answers to your problem in it.





cashdeskmac said:
Thank you for the reply Juan,

but I need to know why this is happening on just my computer. If I type the
same code onto another computer and use Server.Transer or Response.Redirect
it works fine, and so I assume that there is a problem with the settings on
my machine.

Juan T. Llibre said:
Both Response.Redirect and Server.Transfer call Response.End internally,
so you'll have the same problem with either.

Use Server.Execute, instead of Server.Transfer.
That will get rid of your problem.





cashdeskmac said:
Hi Karl,

no, I am using Server.Transfer to go from page to page within my application.

:

Are you using a Response.Redirect after setting the session? If so, take a
look at:
http://weblogs.asp.net/bleroy/archive/2004/08/03/207486.aspx

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/


I have put a string into Session and tried to retrieve it on the next page
I
visit but the Session appears empty. I have exactly the same spelling for
both adding and retrieving the value:

Session["name"] = "john";

On the next page:

txtName.Text = Session["name"];

I tried it with .ToString() and in an if statement to make sure it has a
value but it always shows as null.

I have not modified IIS in any way since installing it ( and I have
checked
that Session is enabled in the IIS console).

This happens in any of the applications I create in Visual Studio .NET
2003.

Can there be anything else preventing me from using Session state?
 
G

Guest

Hi there,

"Cashdeskmac" was trying to help with a problem that has occured on my
computer (thanks Allen!).

I have read the responses from Juan and Karl (thanks also for your
responses) but unfortunately the solutions given do not entirely resolve the
problem.

Yes, when I use Server.Execute instead of Server.Transfer the session state
is maintained. But if I place the appropriate "Response.Redirect" code in (as
stated in both responses), sessions state is not maintained?
For example, if the following code is entered is the following:
Response.Redirect("WebForm.aspx", false);

I get the following exception in the browser:
Server Error in '/WebApplication2' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
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.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:


Line 21: private void Page_Load(object sender, System.EventArgs e)
Line 22: {
Line 23: Label1.Text = "Your name is " + Session["Name"].ToString();
Line 24: }
Line 25:


Source File: c:\inetpub\wwwroot\webapplication2\webform.aspx.cs Line: 23

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an
object.]
WebApplication2.WebForm.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\webapplication2\webform.aspx.cs:23
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()


Thanks again for your help
Jon

Juan T. Llibre said:
Please review this KB :
http://support.microsoft.com/kb/312629/EN-US

Although that KB originated in response to a different problem,
it has the answers to your problem in it.





cashdeskmac said:
Thank you for the reply Juan,

but I need to know why this is happening on just my computer. If I type the
same code onto another computer and use Server.Transer or Response.Redirect
it works fine, and so I assume that there is a problem with the settings on
my machine.

Juan T. Llibre said:
Both Response.Redirect and Server.Transfer call Response.End internally,
so you'll have the same problem with either.

Use Server.Execute, instead of Server.Transfer.
That will get rid of your problem.





Hi Karl,

no, I am using Server.Transfer to go from page to page within my application.

:

Are you using a Response.Redirect after setting the session? If so, take a
look at:
http://weblogs.asp.net/bleroy/archive/2004/08/03/207486.aspx

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/


I have put a string into Session and tried to retrieve it on the next page
I
visit but the Session appears empty. I have exactly the same spelling for
both adding and retrieving the value:

Session["name"] = "john";

On the next page:

txtName.Text = Session["name"];

I tried it with .ToString() and in an if statement to make sure it has a
value but it always shows as null.

I have not modified IIS in any way since installing it ( and I have
checked
that Session is enabled in the IIS console).

This happens in any of the applications I create in Visual Studio .NET
2003.

Can there be anything else preventing me from using Session state?
 
J

Juan T. Llibre

Hi, Jon.

re:
Yes, when I use Server.Execute instead
of Server.Transfer the session state is maintained.

That is correct...and that fixes your problem.

re:
But if I place the appropriate "Response.Redirect" code in (as
stated in both responses), sessions state is not maintained?

Don't use Response.Redirect.
Use Server.Execute *instead* of using Response.Redirect.

re:
But if I place the appropriate "Response.Redirect" code in (as
stated in both responses), sessions state is not maintained?

If you can repro that, bug it at the
Visual Studio and .NET Framework Feedback page :

http://connect.microsoft.com/feedback/default.aspx?SiteID=210




Seven said:
Hi there,

"Cashdeskmac" was trying to help with a problem that has occured on my
computer (thanks Allen!).

I have read the responses from Juan and Karl (thanks also for your
responses) but unfortunately the solutions given do not entirely resolve the
problem.

Yes, when I use Server.Execute instead of Server.Transfer the session state
is maintained. But if I place the appropriate "Response.Redirect" code in (as
stated in both responses), sessions state is not maintained?
For example, if the following code is entered is the following:
Response.Redirect("WebForm.aspx", false);

I get the following exception in the browser:
Server Error in '/WebApplication2' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
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.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:


Line 21: private void Page_Load(object sender, System.EventArgs e)
Line 22: {
Line 23: Label1.Text = "Your name is " + Session["Name"].ToString();
Line 24: }
Line 25:


Source File: c:\inetpub\wwwroot\webapplication2\webform.aspx.cs Line: 23

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an
object.]
WebApplication2.WebForm.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\webapplication2\webform.aspx.cs:23
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()


Thanks again for your help
Jon

Juan T. Llibre said:
Please review this KB :
http://support.microsoft.com/kb/312629/EN-US

Although that KB originated in response to a different problem,
it has the answers to your problem in it.





cashdeskmac said:
Thank you for the reply Juan,

but I need to know why this is happening on just my computer. If I type the
same code onto another computer and use Server.Transer or Response.Redirect
it works fine, and so I assume that there is a problem with the settings on
my machine.

:

Both Response.Redirect and Server.Transfer call Response.End internally,
so you'll have the same problem with either.

Use Server.Execute, instead of Server.Transfer.
That will get rid of your problem.





Hi Karl,

no, I am using Server.Transfer to go from page to page within my application.

:

Are you using a Response.Redirect after setting the session? If so, take a
look at:
http://weblogs.asp.net/bleroy/archive/2004/08/03/207486.aspx

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/


I have put a string into Session and tried to retrieve it on the next page
I
visit but the Session appears empty. I have exactly the same spelling for
both adding and retrieving the value:

Session["name"] = "john";

On the next page:

txtName.Text = Session["name"];

I tried it with .ToString() and in an if statement to make sure it has a
value but it always shows as null.

I have not modified IIS in any way since installing it ( and I have
checked
that Session is enabled in the IIS console).

This happens in any of the applications I create in Visual Studio .NET
2003.

Can there be anything else preventing me from using Session state?
 
G

Guest

Hi Juan,

as Jon pointed out, I posted this in order to solve his problem.

The main issue we have is that when I use Response.Redirect or
Server.Transfer on MY computer, Session variables are maintained without any
problems. It is only on JON's computer that the issue occurs.

Do you know of any setting on his computer which could be to blame?

Juan T. Llibre said:
Hi, Jon.

re:
Yes, when I use Server.Execute instead
of Server.Transfer the session state is maintained.

That is correct...and that fixes your problem.

re:
But if I place the appropriate "Response.Redirect" code in (as
stated in both responses), sessions state is not maintained?

Don't use Response.Redirect.
Use Server.Execute *instead* of using Response.Redirect.

re:
But if I place the appropriate "Response.Redirect" code in (as
stated in both responses), sessions state is not maintained?

If you can repro that, bug it at the
Visual Studio and .NET Framework Feedback page :

http://connect.microsoft.com/feedback/default.aspx?SiteID=210




Seven said:
Hi there,

"Cashdeskmac" was trying to help with a problem that has occured on my
computer (thanks Allen!).

I have read the responses from Juan and Karl (thanks also for your
responses) but unfortunately the solutions given do not entirely resolve the
problem.

Yes, when I use Server.Execute instead of Server.Transfer the session state
is maintained. But if I place the appropriate "Response.Redirect" code in (as
stated in both responses), sessions state is not maintained?
For example, if the following code is entered is the following:
Response.Redirect("WebForm.aspx", false);

I get the following exception in the browser:
Server Error in '/WebApplication2' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
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.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:


Line 21: private void Page_Load(object sender, System.EventArgs e)
Line 22: {
Line 23: Label1.Text = "Your name is " + Session["Name"].ToString();
Line 24: }
Line 25:


Source File: c:\inetpub\wwwroot\webapplication2\webform.aspx.cs Line: 23

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an
object.]
WebApplication2.WebForm.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\webapplication2\webform.aspx.cs:23
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()


Thanks again for your help
Jon

Juan T. Llibre said:
Please review this KB :
http://support.microsoft.com/kb/312629/EN-US

Although that KB originated in response to a different problem,
it has the answers to your problem in it.





Thank you for the reply Juan,

but I need to know why this is happening on just my computer. If I type the
same code onto another computer and use Server.Transer or Response.Redirect
it works fine, and so I assume that there is a problem with the settings on
my machine.

:

Both Response.Redirect and Server.Transfer call Response.End internally,
so you'll have the same problem with either.

Use Server.Execute, instead of Server.Transfer.
That will get rid of your problem.





Hi Karl,

no, I am using Server.Transfer to go from page to page within my application.

:

Are you using a Response.Redirect after setting the session? If so, take a
look at:
http://weblogs.asp.net/bleroy/archive/2004/08/03/207486.aspx

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/


I have put a string into Session and tried to retrieve it on the next page
I
visit but the Session appears empty. I have exactly the same spelling for
both adding and retrieving the value:

Session["name"] = "john";

On the next page:

txtName.Text = Session["name"];

I tried it with .ToString() and in an if statement to make sure it has a
value but it always shows as null.

I have not modified IIS in any way since installing it ( and I have
checked
that Session is enabled in the IIS console).

This happens in any of the applications I create in Visual Studio .NET
2003.

Can there be anything else preventing me from using Session state?
 
G

Guest

Hi,

Just to let you all know that this issue was resolved by either switching
off my zone alarm privacy settings (to allow browsers to accept cookies) or
by changing the "cookieless" setting in the <sessionState> of the web.config
file to "true" so that Session state was maintianed through the URL rather
than through cookies.

Thank you all for your help.

Rgds
Jon

cashdeskmac said:
Hi Juan,

as Jon pointed out, I posted this in order to solve his problem.

The main issue we have is that when I use Response.Redirect or
Server.Transfer on MY computer, Session variables are maintained without any
problems. It is only on JON's computer that the issue occurs.

Do you know of any setting on his computer which could be to blame?

Juan T. Llibre said:
Hi, Jon.

re:
Yes, when I use Server.Execute instead
of Server.Transfer the session state is maintained.

That is correct...and that fixes your problem.

re:
But if I place the appropriate "Response.Redirect" code in (as
stated in both responses), sessions state is not maintained?

Don't use Response.Redirect.
Use Server.Execute *instead* of using Response.Redirect.

re:
But if I place the appropriate "Response.Redirect" code in (as
stated in both responses), sessions state is not maintained?

If you can repro that, bug it at the
Visual Studio and .NET Framework Feedback page :

http://connect.microsoft.com/feedback/default.aspx?SiteID=210




Seven said:
Hi there,

"Cashdeskmac" was trying to help with a problem that has occured on my
computer (thanks Allen!).

I have read the responses from Juan and Karl (thanks also for your
responses) but unfortunately the solutions given do not entirely resolve the
problem.

Yes, when I use Server.Execute instead of Server.Transfer the session state
is maintained. But if I place the appropriate "Response.Redirect" code in (as
stated in both responses), sessions state is not maintained?
For example, if the following code is entered is the following:
Response.Redirect("WebForm.aspx", false);

I get the following exception in the browser:
Server Error in '/WebApplication2' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
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.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:


Line 21: private void Page_Load(object sender, System.EventArgs e)
Line 22: {
Line 23: Label1.Text = "Your name is " + Session["Name"].ToString();
Line 24: }
Line 25:


Source File: c:\inetpub\wwwroot\webapplication2\webform.aspx.cs Line: 23

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an
object.]
WebApplication2.WebForm.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\webapplication2\webform.aspx.cs:23
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()


Thanks again for your help
Jon

:

Please review this KB :
http://support.microsoft.com/kb/312629/EN-US

Although that KB originated in response to a different problem,
it has the answers to your problem in it.





Thank you for the reply Juan,

but I need to know why this is happening on just my computer. If I type the
same code onto another computer and use Server.Transer or Response.Redirect
it works fine, and so I assume that there is a problem with the settings on
my machine.

:

Both Response.Redirect and Server.Transfer call Response.End internally,
so you'll have the same problem with either.

Use Server.Execute, instead of Server.Transfer.
That will get rid of your problem.





Hi Karl,

no, I am using Server.Transfer to go from page to page within my application.

:

Are you using a Response.Redirect after setting the session? If so, take a
look at:
http://weblogs.asp.net/bleroy/archive/2004/08/03/207486.aspx

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/


I have put a string into Session and tried to retrieve it on the next page
I
visit but the Session appears empty. I have exactly the same spelling for
both adding and retrieving the value:

Session["name"] = "john";

On the next page:

txtName.Text = Session["name"];

I tried it with .ToString() and in an if statement to make sure it has a
value but it always shows as null.

I have not modified IIS in any way since installing it ( and I have
checked
that Session is enabled in the IIS console).

This happens in any of the applications I create in Visual Studio .NET
2003.

Can there be anything else preventing me from using Session state?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,166
Latest member
DollyBff32
Top