0

I am working on redirecting users to maintenance page based on their IP address.
For this, I have a Vf page embedded in the lightning aura component. On load of Vf page, an apex method needs to be invoked and get the IPAddress as a string. The IPAddress needs to be passed to a lightning component(aura) which can access it in its init method.

Any pointers on implementing the above is highly appreciated.

Please find below the code used:

  1. On load of Vf page, call the apex controller to fetch the IP address of the portal user in a String variable, say ipAddr.

ControllerCls(Apex class)

public class ControllerCls
{
    public String ipAddr { get; set; }
    public void String getIP()
    {
        ipAddr = fetchIP();//I didnt include fetchIP() method here as it makes no difference
    }
}

VfPage

<apex:page showHeader="false" sidebar="false" controller="ControllerCls" onload="{!getIP}">
</apex:page>
  1. Embed the above Vf page in a aura component and pass the variable ipAddr from Vf page to the aura component which embeds the above Vf page. The ipAddr variable needs to be available to the aura component in its init method so as to proceed with other processing.

Aura Component

    <aura:component implements="forceCommunity:availableForAllPageTypes" access="global">
        <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
        <iframe src="{!'/apex/VfPage1'}"/>
    </aura:component>

JS Controller

({
  doInit: function doInit(component, event, helper) {
    //Use ipAddr variable from the embedded Vf page for processing  
  }
});

How do I pass this variable ipAddr from Vf page to the aura component?

1 Answer 1

-1
  1. Please refer below link to get IP in VF get IP

  2. Refere below link to get value in aura from VF this

3
  • 2
    While this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
    – identigral
    Mar 26, 2022 at 18:46
  • The reason for this dislike of link-only answers is that links tend to get broken over time.
    – Phil W
    Mar 26, 2022 at 19:11
  • Thanks for the answers but we are embedding Vf in lightning component not the other way. We are using Vf page only to get the IP address of the current portal user(because this works properly for both registered and guest users). I updated the question.
    – Suhasini
    Mar 27, 2022 at 12:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .