Daniele Teti 2022-03-25 11:02:09 +01:00
parent c2d3cbc859
commit 78ef7c01a9
3 changed files with 19 additions and 11 deletions

View File

@ -703,6 +703,8 @@ The current beta release is named 3.2.2-nitrogen. If you want to stay on the-edg
- Fix https://github.com/danieleteti/delphimvcframework/issues/526 (Thanks to [David Moorhouse](https://github.com/fastbike))
- Fix https://github.com/danieleteti/delphimvcframework/issues/544 (Thanks to [David Moorhouse](https://github.com/fastbike))
- Fix https://github.com/danieleteti/delphimvcframework/issues/542 (Thanks to [Lamberto Lodi](https://github.com/llodi-csw) for the hints)
- Fixed *fileupload* sample

View File

@ -955,7 +955,7 @@ type
function ExecuteAction(const ASender: TObject; const ARequest: TWebRequest;
const AResponse: TWebResponse): Boolean; virtual;
public
class function GetCurrentSession(const ASessionTimeout: Integer; const ASessionId: string;
class function GetCurrentSession(const ASessionId: string;
const ARaiseExceptionIfExpired: Boolean = True): TWebSession; static;
class function ExtractSessionIdFromWebRequest(const AWebRequest: TWebRequest): string; static;
class function SendSessionCookie(const AContext: TWebContext): string; overload; static;
@ -1907,8 +1907,7 @@ procedure TWebContext.BindToSession(const ASessionId: string);
begin
if not Assigned(FWebSession) then
begin
FWebSession := TMVCEngine.GetCurrentSession(StrToInt64(FConfig[TMVCConfigKey.SessionTimeout]),
ASessionId, False);
FWebSession := TMVCEngine.GetCurrentSession(ASessionId, False);
if not Assigned(FWebSession) then
raise EMVCException.Create('Invalid SessionID');
FWebSession.MarkAsUsed;
@ -2070,7 +2069,7 @@ function TWebContext.GetWebSession: TWebSession;
begin
if not Assigned(FWebSession) then
begin
FWebSession := TMVCEngine.GetCurrentSession(StrToInt64(FConfig[TMVCConfigKey.SessionTimeout]),
FWebSession := TMVCEngine.GetCurrentSession(
TMVCEngine.ExtractSessionIdFromWebRequest(FRequest.RawWebRequest), False);
if not Assigned(FWebSession) then
SessionStart
@ -2148,8 +2147,17 @@ begin
TMonitor.Enter(GlobalSessionList);
try
SId := TMVCEngine.ExtractSessionIdFromWebRequest(FRequest.RawWebRequest);
SID := SessionId;
if (SId = '') and (ARaiseExceptionIfExpired) then
begin
raise EMVCSessionExpiredException.Create('Session not started');
end;
//SId := TMVCEngine.ExtractSessionIdFromWebRequest(FRequest.RawWebRequest);
GlobalSessionList.Remove(SId);
if SId <> '' then
begin
FWebSession := nil;
end;
finally
TMonitor.Exit(GlobalSessionList);
end;
@ -2488,7 +2496,7 @@ begin
begin
Log.ErrorFmt('[%s] %s (Custom message: "%s")', [ESess.Classname, ESess.Message,
ESess.DetailedMessage], LOGGERPRO_TAG);
lContext.SessionStop(False);
lContext.SessionStop;
lSelectedController.ResponseStatus(ESess.HTTPErrorCode);
lSelectedController.Render(ESess);
end;
@ -2894,8 +2902,7 @@ begin
end;
end;
class function TMVCEngine.GetCurrentSession(const ASessionTimeout: Integer;
const ASessionId: string; const ARaiseExceptionIfExpired: Boolean): TWebSession;
class function TMVCEngine.GetCurrentSession(const ASessionId: string; const ARaiseExceptionIfExpired: Boolean): TWebSession;
var lSessionList: TObjectDictionary<string, TWebSession>;
begin
Result := nil;
@ -2932,8 +2939,7 @@ end;
function TMVCEngine.GetSessionBySessionId(const ASessionId: string): TWebSession;
begin
Result := TMVCEngine.GetCurrentSession(StrToInt64(Config[TMVCConfigKey.SessionTimeout]),
ASessionId, False);
Result := TMVCEngine.GetCurrentSession(ASessionId, False);
if Assigned(Result) then
Result.MarkAsUsed;
end;

View File

@ -553,7 +553,7 @@ procedure TTestServerController.Logout;
begin
if not Context.SessionStarted then
raise EMVCException.Create('Session not available');
Context.SessionStop(false);
Context.SessionStop;
if Context.SessionStarted then
raise EMVCException.Create('Session still available');
end;