Initial post
I've posted about my issue on the Mojolicious forum but am still looking for a solution.
For various reasons I'm trying to get some Mojolicious apps I've written to run on IIS. I have a 7.5 (2k8r2) and 8.5 (2k12r2) server to test with.
The IIS setup is very basic. I created a new application under the Default Web Site, pointed it to the code, added the Perl Handler Mapping, and added a default document. The path to the site is http://server.example.com/sessiontest/
After getting the site setup and running, everything is working as expected except that sessions are not working. I wrote a test app to test with. At the start of the script I'm setting up the session:
# Setup sessions
app->secrets(['SessionTest']);
app->sessions->cookie_name('sessiontest');
Setting the session variable:
get '/set' => sub {
my $c = shift;
$c->session(testvar => 1);
$c->redirect_to('/');
};
And testing to see if it exists with a helper:
helper testvar => sub {
my $c = shift;
if($c->session('testvar')) {
return 1;
}
return undef;
};
When I run the code with Morbo on either server it runs fine and sessions are working. But under IIS I get nothing.
One of the suggestions I received was to look at the cookie domain and cookie path. As a test I tried setting a test domain name in the hosts file of the server and the client for the servers IP at test.example.com
. I them added:
app->sessions->cookie_domain('.example.com');
app->sessions->cookie_path('/sessiontest');
I'm assuming the cookie_path
should be '/' which I have also tried with no luck.
Any help would be appreciated!
IIS Config
This is a freshly installed W2k12R2 box running IIS 8.5. I have ActivePerl 5.24 installed. The config is as basic as I can get. Here's the steps I took to configure IIS.
- Install IIS w/ CGI support
- Copy test app to C:\Code\sessiontest\
- From Default Web Site -> Add Application
- Alias: sessiontest, Physical path: C:\Code\sessiontest\
- Select sessiontest application
- Add Handler Mapping for *.pl to C:\Perl64\bin\perl.exe "%s" %s
- Add Default Document for app.pl
Output from curl
Result from curl to the IIS server.
curl -I http://server.example.com/sessiontest/app.pl/set
HTTP/1.1 200 OK
Content-Length: 160
Content-Type: text/html;charset=UTF-8
Server: Microsoft-IIS/7.5
[Thu Aug 3 19: 49:38 2017] [debug] HEAD "/"
[Thu Aug 3 19: 49:38 2017] [debug] Routing to a callback
[Thu Aug 3 19: 49:38 2017] [debug] Rendering template "index.html.ep" from DATA section
[Thu Aug 3 19: 49:38 2017] [debug] Rendering template "layouts/default.html.ep" from DATA section
[Thu Aug 3 19: 49:38 2017] [debug] 200 OK (0.002271s, 440.335/s)
Date: Thu, 03 Aug 2017 23:49:38 GMT
Versus the result of running from Morbo
curl -I http://server.example.com:3000/set
HTTP/1.1 302 Found
Content-Length: 0
Date: Thu, 03 Aug 2017 23:51:29 GMT
Location: /
Server: Mojolicious (Perl)
Set-Cookie: sessiontest=eyJleHBpcmVzIjoxNTAxODA3ODg5LCJ0ZXN0dmFyIjoxfQ----96063fca63a3457e89becc55d7df39898466bb99; expires=Fri, 04 Aug 2017 00:51:29 GMT; path=/; HttpOnly
I set the mode to production and now I'm getting something closer on IIS.
curl -I http://server.example.com/sessiontest/app.pl/set
HTTP/1.1 200 OK
Content-Length: 160
Content-Type: text/html;charset=UTF-8
Server: Microsoft-IIS/7.5
Date: Fri, 04 Aug 2017 00:04:30 GMT