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
Gaurav GulanjkarGaurav Gulanjkar 

Login method invoking error

Hi Guys,

I am trying to do a simple authentication for portal user.I have written a login method and trying to call it from a VF command button.In the debug logs i get a following statement after entering username and password.Its not redirecting to the startUrl mentioned in site.login() call.

09:27:23.073 (73933217)|VF_APEX_CALL|submit|{!login}|PageReference: none

Following is the controller code :

public class MobileSiteLoginController {

public String username {get; set;}
public String password {get; set;}
public User tempUser{get; set;}
public String startUrl{get;set;}

public PageReference login() {
String startUrl = System.currentPageReference().getParameters().get('/MobileAppPage1');  
    System.debug('-----username----'+ username);
    System.debug('-----Password----'+ password);
    System.debug('-----Start URL---'+ startUrl);
    return Site.login(username, password, startUrl);  
}
public MobileSiteLoginController () { }

}

Please let me know if i am doing anything wrong.

Thanks,
Gaurav

Vamsi KrishnaVamsi Krishna
Gaurav,
can you try this and see if it works

public PageReference login() {
String startUrl = System.currentPageReference().getParameters().get('/MobileAppPage1'); 
    System.debug('-----username----'+ username);
    System.debug('-----Password----'+ password);
    System.debug('-----Start URL---'+ startUrl);
    PageReference p = Site.login(username, password, startUrl); 
    if (p!=null)
            p.setRedirect(true);
    return p;

}


        
Gaurav GulanjkarGaurav Gulanjkar
Hi Vamsi,

I modified the controller as above.But i still get the same logs mentioned in previous comment and the page is not redirected to the mentioned start URL.
ra1ra1
Hi,

Could you please try to remove extra "/" before "MobileAppPage1" parameter..

like :
String startUrl = System.currentPageReference().getParameters().get('MobileAppPage1');

May be this will work.

Thanks!!
Gaurav GulanjkarGaurav Gulanjkar
Hi,

I tried to remove the extar '/' but in the logs i get startUrl as null.

Have i missed anything in the settings abt the portal and the sites.

Thanks,
Gaurav