1

Closed

Session is always expired

description

Problem:
Session is always expired when developing on local environment (Azure Compute Emulator) and using Azure Storage (production environment) not UseDevelopmentStorage=true
<sessionState timeout="60">
Problem is DateTime comparison. On the left side is UTC and on the right side is local time.
 
Version 1.6.9726 (Sep 17 2011)
AzureSessionStateProvider.cs (line number 189)
 
var expires = session.Expires;
if (expires < DateTime.Now)
 
Solution:
var expires = session.Expires;
if (expires < DateTime.UtcNow)
Closed Nov 10, 2011 at 4:31 PM by ihenriksen
Can't reproduce.

comments

ihenriksen wrote Nov 10, 2011 at 3:16 PM

I can't recreate this. If I have defined a 20 minute timeout like this:
<sessionState useHostingIdentity="true" compressionEnabled="false" timeout="20" mode="Custom" customProvider="AzureSessionProvider">
  <providers>
    <clear />
    <add name="AzureSessionProvider" type="WebPages.Bll.AzureSessionStateProvider" />
  </providers>
</sessionState>
, and put a debug breakpoint at line 190 in AzureSessionStateProviders.cs's GetSessionStoreItem() method here:
            var expires = session.Expires;
            if (expires < DateTime.Now)
, then there is 20 minutes difference between "expires" and DateTime.Now at startup like the code expects.

ihenriksen wrote Nov 10, 2011 at 3:21 PM

, also, If I use your suggested solution then the difference is 1 hour 20 minute, which is erroneous on my system again.

m_david wrote Nov 10, 2011 at 4:22 PM

You're right. This error is just in my special case.
I'll try to explain it.

My Azure Storage Account is in West Europe region, it means Dublin. There is UTC in Dublin.
I'm in Prague, compute emulator has UTC+1 hour time.

When I create a session it has auto assigned Timestamp. The session has UTC time.
If I compare the expiring time with my local time it's always expired, because I have +1 hour against storage computer.

It's a basic fault.
A man should always use UseDevelopmentStorage=true when working on Azure Emulator.