#1 2020-12-16 06:13:36

missionhq
Member
From: Australia
Registered: 2019-06-11
Posts: 33

How to get Client IP Addr (and other things) in MVC Views

My question is, is it possible to get the clients IP Address (ie the IP Address the clients web browser is running on, or the external IP Address in case of access over the internet) inside the view code.

Eg, in

procedure TMyMVCApplication.Default(var Scope: variant);
begin
  { Need to show the Default page here }
  SetVariantNull(Scope);
end;

Do I have access the the clients IP Address?
Would be interested in other context info too if available.

Offline

#2 2020-12-16 08:09:11

pvn0
Member
From: Slovenia
Registered: 2018-02-12
Posts: 211

Re: How to get Client IP Addr (and other things) in MVC Views

sure, you can access that information like this :

var context: PServiceRunningContext;
begin
  context := @ServiceContext;
  clientIP := context.Request.RemoteIP;

Note that the RemoteIP is empty if localhost.

read the documentation

Offline

#3 2020-12-16 23:22:49

missionhq
Member
From: Australia
Registered: 2019-06-11
Posts: 33

Re: How to get Client IP Addr (and other things) in MVC Views

Perfect! Cheers pvn0

Offline

Board footer

Powered by FluxBB