Simone Nigro
Simone Nigro

Reputation: 4897

Delphi TWebModule (IIS-ISAPI): get the current request

in a TWebModule procedure/function how get the current request?

I have tried:

procedure TWebModule1.DoSomething;
var 
  aRequest : TWebRequest;
begin
  aRequest := Request;
end;

but it seems the first request produced on TWebModule creation.

I know i'm able to pass the request to subsequent Procedures/Functions from each TWebActionItem, but i want avoid to pass the request every where. Any tips?

Update

After digging into the code, i found WebContext and it seems the solution, eg.:

uses Web.WebCntxt;

procedure TWebModule1.DoSomething;
var
  aRequest : TWebRequest;
begin
  if WebContext <> nil then
    aRequest := WebContext.Request;
end;

is it the right way? WebContext seems always nil.

I'm on Delphi Berlin update 2.

Upvotes: 4

Views: 817

Answers (1)

Andreas
Andreas

Reputation: 431

Every Request goes through a TWebActionItem defined in the TWebModule.Actions. The TWebActionItem has an event OnAction. There you will get the TWebRequest Object of the current Request.

Then you are able to pass it to subsequent Procedures/Functions.

Upvotes: 3

Related Questions