adrive has asked for the wisdom of the Perl Monks concerning the following question:

interestingly enough, whenever i try creating a virtual directory with IIS (5.1) - (WinXP), my session objects somehow gets lost somewhere in between pages.

to do this :

1.) create a folder "test" let's say on C:\ and put all teh files inside.
2.) right click on the folder, properties->websharing->share the folder and check everything in checkboxes.
3.) now access testsession.pl with a web browser.
4.) the page will show, with session id, and also it'll show on the next page with its found session object.

5.) now..

6.) go to IIS, under default web site, find "test" virtual directory and set its properties->directory security->anonymous access checked.
7.) apply and restart IIS.

8.) now, try running testsession.pl again...and when you move to the next page, your session is gone!

why is this happening??? (happening to me).

the reason why i wanted to set anonymous access on lower level folder "test" is because it'll prompt me a authentication screen if i use ie6 or firefox when viewing the first page.

file 1 : testsession.pl
#!/usr/bin/perl print "content-type: text/html \n\n"; use CGI; use CGI::Session qw/-ip-match/; use File::Spec; # my $session = new CGI::Session("driver:File", undef, {Directory=>Fil +e::Spec->tmpdir}); my $session = new CGI::Session(); my $sessionid = $session->id(); print "<BODY>"; print " <FORM ACTION=\"testsession2.pl\">"; print "<INPUT TYPE=\"hidden\" NAME=sessionid VALUE=" . $sessionid . "/ +>"; print "current session : " . $sessionid; print "<INPUT TYPE=\"SUBMIT\" VALUE=\"go next\">"; print "</FORM>"; print "</BODY>";


testsession2.pl
#!/usr/bin/perl print "content-type: text/html \n\n"; use CGI; use CGI::Session qw/-ip-match/; my $cgi = new CGI; my $sessionid = $cgi->param("sessionid"); print "current session id ($sessionid)"; my $session = CGI::Session->load($sessionid); if(!$session->is_empty()){ print "<BODY>"; print " <FORM ACTION=\"testsession.pl\">"; print "<br><br>found session object from sessionid : " . $session- +>id(); print "<INPUT TYPE=\"SUBMIT\" VALUE=\"back\">"; print "</FORM>"; print "</BODY>"; }else{ print "<BODY>"; print " <br><br>weird enough...session object is lost!"; print "</BODY>"; }

Replies are listed 'Best First'.
Re: CGI::Session not saving with IIS
by moritz (Cardinal) on Mar 11, 2008 at 09:53 UTC
    You try to receive the session ID via $cgi->param('sessionid'), but you never provide a session ID parameter in the URL or in a POST request.

    Try this:

    my $self_url = $cgi->self_url() print qq{<a href="$self_url?session_id=$session_id">next page</a>\n}

    And then use "next page" link. (Later on you should move the session ID to a cookie, but for texting the URL is fine).

    Also please remeber to call ->flush() on your session object to actually store it to disk.

Re: CGI::Session not saving with IIS
by adrive (Scribe) on Mar 11, 2008 at 12:05 UTC
    actually it's not the problem of not being able to pass my session id, if you noticed, i've included sessionid as a hidden field on the first page.

    i'm able to receive the similiar session id on the 2nd page, but it can't seem to load or can't find the previously created session object. I've also tried putting $session->flush(); on first page, but it didn't work either....

      I missed the hidden field (btw your HTML could be improved greatly, for example attribute values should be quoted with double quotes).

      For debugging you can try to set a specific data source name (for example to a folder) and then check that data source manually. That way you can find out if the problem is session storage or retrieval.

        well the codes were written up as a demo to show the problem so it'll look a little weird..

        but, what do you mean by setting data source up? there isn't any database involved in the example though. You could try the step by step instructions to regenerate the problem.