You need to sign in to do that
Don't have an account?

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!
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.
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>
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>
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>
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.