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.
Juan T. Llibre, asp.net MVP
aspnetfaq.com :
http://www.aspnetfaq.com/
asp.net faq :
http://asp.net.do/faq/
foros de asp.net, en español :
http://asp.net.do/foros/
===================================
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.
Juan T. Llibre, asp.net MVP
aspnetfaq.com :
http://www.aspnetfaq.com/
asp.net faq :
http://asp.net.do/faq/
foros de asp.net, en español :
http://asp.net.do/foros/
===================================
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?