views:

109

answers:

1

Hello,

I've got a problem losing session variables in an ASP/VB.NET application.

The application allows searching for an item or it can show an item if provided with a unique link (in the browser). It holds information about the item in session variables.

In the webpage showing an Item a user can click a button which opens a window with additional information about the item – obtained from a session variable.

When I search for the item using the search engine and click the button – it works OK.

When I copy the link to a browser: the item is shown, however clicking the button returns a ‘null exception’ – the session variables with information about the item are lost. Moreover when I provide the link for the second time the button works, the variables are there!!!

Does anyone has any idea why this can be happening?

+1  A: 

Sounds like an edge case where the Session("your_variable") isn't being initilized correctly based on the link information.

Things to investigate:

Is the page being served off the cache when you provide the link initially? ASP.NET will cache content and not execute the server-side code because the page isn't being created again on the request. If you have code that initilizes some state when the page is loaded that is later referred to when the button is clicked, that indeed could be your problem.

Achilles