I have two web forms in ASP.net. In the first page is set a session variable like so:
HttpContext.Current.Session("myTestVariable") = "ABCD"
On the second page I try to read the session variable like so:
dim myString as string = HttpContext.Current.Session("myTestVariable")
The string is null on the second page.
In web.config I have the following entry:
sessionState mode="InProc" timeout="60"
What am I missing?
2
Answers
I could not get this working. Maybe something to do with my unique development environment. Based on my experience, I have now implemented a REDIS database for all my session variable needs. This seems to be working satisfactory.
As an old programmer, I find it hard when things are not under my direct control. I trust that ASP.NET will fail from time-to-time. I can't take the risk that my hours of testing in a Development environment does not translate to the production environment. Managed hosts are the way to go. But you have no control over the integrity of the production environment.
What you have looks correct.
So, say in PageA.aspx, I have this markup:
And code behind for the button is:
And on PageB.aspx, this markup:
And code behind for PageB.aspx is:
Hence, the result is this:
So, there must be some additional information you are leaving out, as we are unable to reproduce your error.
What you have looks just fine.
Does the above sample code not work say on your developer computer, but fails on the production server?