function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ramcrramcr 

How to capture header URL in the apex controller

Hi Friends,

 

I am new to salesforce. My requirement is that we are using our own LDAP authentication. Upon successful authentication it should redirect the user to salesforce free site url but before it hits free site URL I wanted to check in  the header URL to grab the HOST so that I can determine from where the request is coming from and if i found the reqest  is coming from valid HOST then i will let the user to see our free site page otherwise will show him the error page.

 

Note : We want to use salesforce free site.

 

Any suggestions would be really help full.

 

Thanks Guys!

 

RyanGuestRyanGuest

 

ApexPages.currentPage().getHeaders().get('Host');

 

 

ramcrramcr

Thanks Ryan for your quick response. I really appreciate it.

 

I tried to implement ApexPages.currentPage().getHeaders().get('Host'); in my controller but found that it will not work in my case because like i said our company LDAP will hit the salesforce free sit url.

 

It seems that i have to write ApexPages.currentPage().getHeaders().get('Host') functionality in visual source page onload function in order to capture LDAP source url.

 

 

LDAP-----> VisualSource Free Site URL

 

It seems i don't even need to use controller for this. And just capture the LDAP source URL in visualsource itself.

 

But so far i am not able achieve this in visualsource because it seems there is no onload event in <apex:actionSupport

 

Below find the code i am trying :

 

<apex:page setup="true" controller="MyController" showHeader="false">
<apex:form >
 <apex:outputpanel id="counter">
 <apex:outputText value="Click Here To Generate Session Id and Server URL" />
 <apex:actionSupport event="onload" action="{!doLogin}" rerender="refreshId" status="counterStatus">
 <apex:param name="serverHostURL" assignTo="{!apiHostURL}" value="{!$Site.OriginalUrl}" />
 </apex:actionSupport>
 </apex:outputpanel><br></br>
 <apex:outputPanel id="refreshId">
  <apex:outputText value="API1 Server Host: {!apiHostURL}"/><br></br>
 </apex:outputPanel>
</apex:form>
</apex:page>

 

Please let me know what i am doing wrong here.

 

Once again thanks for your reply.

 

 

lodoss1118lodoss1118

try........

 

<apex:page setup="true" controller="MyController" showHeader="false">
<apex:form >

<apex:actionFunction name="GetUrl" rerender="refreshId">

      <apex:param name="serverHostURL" assignTo="{!apiHostURL}" value="{!$Site.OriginalUrl}" />

</apex:actionFunction>
 </br>
 <apex:outputPanel id="refreshId">
  <apex:outputText value="API1 Server Host: {!apiHostURL}"/><br></br>
 </apex:outputPanel>
</apex:form>

<script>

     window.onload = GetUrl();
</script>

</apex:page>

ramcrramcr

As suggested  tried below code but its showing blank url with a java scirpt error on the page. Please let me know if i am doing anything wrong 

 

Java Script Error :

 

Line : 9

Char: 6

Error : Not Implemented :

 

 

 

Controller :

 

public class MyController {

 public String apiHostURL {get;set;}
 
 public PageReference doLogin(){ 
  System.debug('apiHostUrl: ' + apiHostURL);  
  return null;  
  }
  
 }

 

 

visualforce :

 

<apex:page setup="true" controller="MyController" showHeader="false">
<apex:form >

<apex:actionFunction name="GetUrl" rerender="refreshId">

      <apex:param name="serverHostURL" assignTo="{!apiHostURL}" value="{!$Site.OriginalUrl}" />

</apex:actionFunction>

<apex:outputPanel id="refreshId">
  <apex:outputText value="API Server Host: {!apiHostURL}"/><br></br>
</apex:outputPanel>

</apex:form>
<script>
     window.onload = GetUrl();
</script>

</apex:page>

 

lodoss1118lodoss1118

try.........

 

public class MyController {

 public String apiHostURL {get;set;}
 
 public PageReference doLogin(){ 
  apiHostURL = ApexPages.getCurrentPage().getParameters().get('serverHostURL');
  return null;  
  }
  
 }

 

<apex:page setup="true" controller="MyController" showHeader="false">
<apex:form >

<apex:actionFunction name="GetUrl" action="{!doLogin}" rerender="refreshId">
      <apex:param name="serverHostURL"  value="{!$Site.OriginalUrl}" />
</apex:actionFunction>

<apex:outputPanel id="refreshId">
  <apex:outputText value="API Server Host: {!apiHostURL}"/><br></br>
</apex:outputPanel>

</apex:form>
<script>
     window.onload = GetUrl();
</script>

</apex:page>

ramcrramcr

Really appriciate your prompt responses.

 

On the page I am still getting the host url value as blank.

 

on the page it giving following java script error :

 

Line : 9

Char: 6

Error: Not Implemented

 

Not sure what is this error for.