ASP Classic Session Variable Not Always Getting Set

asp-classic

I have a classic ASP site I'm maintaining and recently we wanted to do special rendering actions if the visitor was coming from one specific set of websites. So in the page where those visitors have to come through to get to our site, I put a simple line setting a 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, whenever I need to put up nav links, menus, etc., that we don't want to show to those visitors, I test for if that session variable is "" or not, then render accordingly.

My problem is that it seems to work great for me in development, then I get it out into Production and it works great sometimes, and other times it doesn't work at all. Sometimes the session variable gets set, sometimes it doesn't. Everything else works great. But our client is seeing inconsistent results on pages rendered to their visitors and this is a problem. I've tried logging on from different PC's and I confirm that I get different, and unpredictable, results. The problem is I can't reproduce it at will, and I can't troubleshoot/trace Production.

For now I've solved this by just creating duplicate pages with the special rendering, and making sure those visitors go there. But this is a hack and will eventually be difficult to maintain.

Is there something special or inconsistent about session variables in Classic ASP? Is there a better way to approach the problem? TIA.

Update
I have discovered that the first time you visit the site through that page, the session variable does NOT get set. The menus and everything (that are supposed to not appear in those cases) show up the first time through. Then, if you go back and refresh the login page, go through it again to the very same page, this time it works, and thereafter. Then I went and deleted out all my caching, cookies, etc. and hit the login page again, got to my page: Bam, menus (i.e. no session variable) again. I created a page, "sessionvars.asp" where I display the contents of that var and sure enough, it's blank. At least now that I can reproduce the problem at will, I should be able to duplicate it on Dev and track it down.

Best Answer

I was having the same problem with a VPS server. You can't use a Web Garden with Session variables in classic ASP.

Go to IIS Manager - Web Applicattion Pool and Change the number of Worker Process to 1.

If you are in a shared hosting ask for this configuration or change to an Application Pool with ohly one worker.

More info: http://bytes.com/topic/asp-classic/answers/54826-asp-sessions-web-gardens

Regards

www.imaginacolombia.com

Related Topic