Skip to content

Commit da62076

Browse files
author
sjuarez
committed
Fix session management
1 parent c2a6d05 commit da62076

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

dotnet/src/extensions/Azure/Libraries/HttpHandler/GXAzureRestServices.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using GeneXus.Application;
55
using GeneXus.Cache;
66
using GeneXus.Deploy.AzureFunctions.HttpHandler;
7+
using GeneXus.Http;
78
using GeneXus.Utils;
89
using Microsoft.AspNetCore.Http;
910

@@ -24,6 +25,7 @@ protected void setInitialization(HttpContext httpContext)
2425
{
2526
_httpContext = httpContext;
2627
context = GxContext.CreateDefaultInstance();
28+
context.HttpContext = GetHttpContext();
2729
SetServiceSession(httpContext.Request, httpContext.Response, httpContext);
2830

2931
}
@@ -52,7 +54,11 @@ private void SetServiceSession(HttpRequest request, HttpResponse response, HttpC
5254
{
5355
GXHttpAzureContext httpAzureContext = new GXHttpAzureContext(_httpContext.Request, _httpContext.Response, _cacheService);
5456
if (httpAzureContext != null && httpAzureContext.Session != null)
57+
{
5558
_httpContext.Session = httpAzureContext.Session;
59+
context.HttpContext.NewSessionCheck();
60+
}
61+
5662
else
5763
GXLogging.Debug(log, $"Error : Azure Serverless session could not be created.");
5864
}

dotnet/src/extensions/Azure/Libraries/HttpHandler/GXHttpAzureContext.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using GeneXus.Configuration;
99
using GeneXus.Utils;
1010
using Microsoft.AspNetCore.Http;
11-
using Microsoft.Azure.Functions.Worker.Http;
1211
using StackExchange.Redis;
1312

1413
namespace GeneXus.Deploy.AzureFunctions.HttpHandler
@@ -17,12 +16,19 @@ public class GXHttpAzureContext
1716
{
1817
private ICacheService2 _redis;
1918
private string sessionId;
20-
private ISession session;
2119
private static readonly IGXLogger log = GXLoggerFactory.GetLogger<GXHttpAzureContext>();
2220
internal const string AZURE_SESSIONID = "GX_AZURE_SESSIONID";
2321

24-
public ISession Session => session;
25-
22+
public ISession Session
23+
{
24+
get
25+
{
26+
if ((_redis != null) & (sessionId != null))
27+
return new RedisHttpSession(_redis, sessionId);
28+
else return new MockHttpSession();
29+
}
30+
}
31+
2632
public GXHttpAzureContext( HttpRequest request, HttpResponse response, ICacheService2 redis)
2733
{
2834
bool isSecure = IsSecureConnection(request);
@@ -35,17 +41,12 @@ public GXHttpAzureContext( HttpRequest request, HttpResponse response, ICacheSer
3541

3642
if (string.IsNullOrEmpty(sessionId) && request != null)
3743
CreateSessionId(isSecure, response, request);
38-
39-
if ((_redis != null) && (sessionId != null))
40-
session = new RedisHttpSession(_redis, sessionId);
41-
else
42-
session = new MockHttpSession();
4344

4445
if (!string.IsNullOrEmpty(sessionId))
4546
{//Refresh the session timestamp
46-
if (session is RedisHttpSession)
47+
if (Session is RedisHttpSession)
4748
{
48-
RedisHttpSession redisHttpSession = (RedisHttpSession)session;
49+
RedisHttpSession redisHttpSession = (RedisHttpSession)Session;
4950
//Check if session is in cache
5051
if (redisHttpSession.SessionKeyExists(sessionId))
5152
{
@@ -55,7 +56,6 @@ public GXHttpAzureContext( HttpRequest request, HttpResponse response, ICacheSer
5556
}
5657
}
5758
}
58-
5959
}
6060
private bool GetSecureConnection(string headerKey, string headerValue)
6161
{

0 commit comments

Comments
 (0)