Classic ASP session variable is not always set
I have a classic ASP site that I maintain and recently we wanted to do special render operations if the visitor came from one specific set of websites. Therefore, on the page where these visitors must go to get to our site, I put a simple line that sets the session variable:
<!-- #include virtual="/clsdbAccess.cs"-->
<%
set db = new dbAccess
%>
<html>
<head>
...
<script language="javascript" type="text/javascript">
...
</script>
</head>
<body>
<%
Session("CAME_FROM_NEWSPAPER") = "your local newspaper"
...
%>
... html stuff ...
</body>
</html>
Then, in all the following pages, when I need to place navigation links, menus, etc. that we don't want to show to these visitors, I check if this session variable is "" or not, then render accordingly.
My problem is that it seems to me that it works great for me during development and then I get it in Production and it works great sometimes and other times it doesn't work at all. Sometimes a session variable is set, sometimes it isn't. Everything else works great. But our client sees inconsistent results on the pages provided to their visitors, and that's a problem. I have tried logging in from different PCs and I confirm that I get different and unpredictable results. The problem is that I cannot reproduce it on my own and I cannot eliminate / track Production.
So far I have solved this by simply creating duplicate pages with custom rendering and making sure those visitors go there. But this is a hack and will eventually be difficult to maintain.
Is there anything special or inconsistent about session variables in classic ASP? Is there a better way to approach the problem? TIA.
Update I found that the first time I visit the site through this page, the session variable is NOT set. The menu and everything (which should not appear in these cases) appears for the first time. Then if you go back and refresh the login page, navigate to the same page, this time it works and then. Then I went and deleted all my caching, cookies, etc. And hit the login page again, went to my page: Bam, menu (i.e. Session Variable) again. I created a page "sessionvars.asp" where I display the contents of this var and of course empty. At least now that I can reproduce the issue as I see fit, I should be able to duplicate it on Dev and track it down.
a source to share
I had the same problem with a VPS server. You cannot use web garden with session variables in classic ASP.
Go to IIS Manager - Web Application Pool and change the number of worker processes to 1.
If you are on shared hosting ask for this config or change it to ohly one worker app pool.
More information: http://bytes.com/topic/asp-classic/answers/54826-asp-sessions-web-gardens
Hello
a source to share
I see a couple of scenarios where this can happen:
The first is mostly echoes @RobV's comment, but the essence of ASP sessions depends on the cookies stored in the browser client. So if a user comes from a client that has cookies disabled, you won't be able to get any session variables for that client.
Another scenario is that some user sessions might be disconnected. For example, let's say the user navigates to a page setting a session variable (and your session timed out, say 10 minutes). Then they go outside and get coffee or get into a conversation. The user then clicks on the link from their page after 30 minutes, at which time the session is canceled. You can try increasing the session timeout and see if that improves the situation.
One workaround would be - instead of a session-based approach - check the client referring URL (HTTP_REFERRER) and see if it is one of the addresses you think is "local newspaper". This may be more work (and some browsers hide the link anyway), but may give better results. Heck, you can try a mix of both: session and referrer.
a source to share